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
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With