Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the django command to delete all tables?

Tags:

django

Are there django commands that

A. Delete all tables

B. delete all data in all tables

C. Create all tables as defined in the model?

I cannot find these right now!

And by commands i mean those little things that are like

runserver 

etc

like image 890
bharal Avatar asked May 15 '12 17:05

bharal


People also ask

How delete all data Django?

If you want to remove all the data from all your tables, you might want to try the command python manage.py flush . This will delete all of the data in your tables, but the tables themselves will still exist. He did say "all the data from all your tables", which should indicate that it's a very destructive operation.

Can we delete all tables?

If you want to use only one SQL query to delete all tables you can use this: EXEC sp_MSforeachtable @command1 = "DROP TABLE ?" This is a hidden Stored Procedure in sql server, and will be executed for each table in the database you're connected.


1 Answers

A. Delete all tables

manage.py sqlclear will print the sql statement to drop all tables

B. delete all data in all tables

manage.py flush returns the database to the state it was in immediately after syncdb was executed

C. Create all tables as defined in the model?

manage.py syncdb Creates the database tables for all apps in INSTALLED_APPS whose tables have not already been created.

See this page for a reference of all commands: https://docs.djangoproject.com/en/dev/ref/django-admin/

But you should definitely look into using south as someone already mentioned. It's the best way to manage your database.

N.B: syncdb is deprecated in favour of migrate, since Django 1.7.

like image 91
nates Avatar answered Sep 22 '22 23:09

nates