question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create a manage.py command to truncate all tables

See original GitHub issue

We 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:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chidcommented, Jun 16, 2016

Please correct me if I’m wrong. Does python manage.py sqlflush | python manage.py dbshell do the job?

0reactions
trbscommented, Aug 27, 2018

closing due to inactivity

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found