Create a manage.py command to truncate all tables
See original GitHub issueWe currently have reset_db
, but when I am creating my test databases, I have to run manage.py migrate
afterwards, and that takes a few seconds.
And even worse, I can’t drop tables on Heroku: https://github.com/django-extensions/django-extensions/issues/909
It would be faster if I could just truncate
all tables instead.
Update: I’m not happy with python manage.py sqlflush | python manage.py dbshell
because it does a DELETE
, which could be slower, and does not reset primary key indexes, which makes it harder to setup my test database that uses explicit indexes.
Related: http://stackoverflow.com/questions/2988997/how-do-i-truncate-table-using-django-orm
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
What is the django command to delete all tables?
A. Delete all tables. manage.py sqlclear will print the sql statement to drop all tables. B. delete all data in all tables.
Read more >Clearing the database with Django commands
contrib. We can actually execute these SQL statements, and thus wipe out all the DB tables in our database, by running: $ python...
Read more >5. How to perform truncate like operation using Django ORM?
Though Django doesn't provide a builtin to truncate a table, ... Category.objects.all().count() 7 >>> Category.objects.all().delete() (7, {'entity.
Read more >How to truncate all tables in MySQL? - TablePlus
Connect to the target database; Select all tables from the left panel; Right-click and choose truncate; Hit Cmd + S to commit changes...
Read more >Truncate all tables in a SQL Server database
Create a table variable to store the constraint drop and creation scripts for the database · Load the data for all tables in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please correct me if I’m wrong. Does
python manage.py sqlflush | python manage.py dbshell
do the job?closing due to inactivity