Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emptying the database through Django's `manage.py`

I would like to completely empty the entire database, restoring it to the way it was when I just created it, using Django's manage.py. Possible?

like image 778
Ram Rachum Avatar asked Oct 26 '11 18:10

Ram Rachum


2 Answers

What you can do to flush the DB and not have any migrate(south) problem afterwards is:

first, reset the data from the DB:

python manage.py flush

second, fake the migrations that are already applied:

python manage.py migrate --fake

third, if you have some fixture to load:

python manage.py loaddata my_sweet_json_file
like image 135
Arthur Neves Avatar answered Sep 28 '22 10:09

Arthur Neves


Yes, you can use flush.

That will reset and restore everything in your entire database, regardless of which app or project the models are in. If you have a few databases, you can specify a single one in particular by using the --database switch

Examples:

python manage.py flush
python manage.py flush --database mydatabase
like image 40
Jordan Avatar answered Sep 28 '22 08:09

Jordan