Active March 21, 2022 / Viewed 52 / Comments 0 / Edit
Example of how to drop a table in a database with django:
In the terminal go the the folder with the manage.py file and then enter the following command:
python manage.py dbshell
It is going to start a shell associated with the database type. For example with the default SQLite it will returns:
SQLite version 3.35.4 2021-04-02 15:20:15
Enter ".help" for usage hints.
sqlite>
To get all table names just enter:
sqlite> .tables
it will returns for example:
sqlite> .tables
auth_group
auth_group_permissions
auth_permission
auth_user
auth_user_groups
myapp_article
To get the number of rows in a table
sqlite> SELECT COUNT(*) FROM myapp_article;
1563
To drop a table:
DROP TABLE myapp_article;
Hi, I am Ben.
I have developed this web site from scratch with Django to share with everyone my notes. If you have any ideas or suggestions to improve the site, let me know ! (you can contact me using the form in the welcome page). Thanks!