Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to roll back all django app migrations?

Tags:

django

I'm bootstrapping a new django project, and my team usually makes a 'setup/reset' script that rebuilds containers as well as drops(unless it doesnt exist yet) and rebuilds the database from scratch.

I found the manage.py flush command for dropping the data, but I also want to revert all migrations. I could only find a command for rolling back the migrations of a single app at a time:

manage.py migrate <app_name> zero

Is there a way I can do that for every app, or would I have to list them out in the script? We do have the manage.py migrate command that migrates everything, so I basically just want the opposite of that.

If it's not easily possible, I'll probably just make the db container drop and rebuild the database

Thanks!

like image 427
hoylemd Avatar asked Nov 16 '18 19:11

hoylemd


1 Answers

The good way is to use Django tools :

python manage.py migrate my_app zero

To reverse the migrations in the database Reversing migrations : Django doc

Then, manually delete the migrations you don't need in my_app/migrations

And finally, your are back to clean project :

python manage.py makemigrations my_app
python manage.py migrate my_app

Enjoy !!

like image 115
gxmad Avatar answered Sep 22 '22 10:09

gxmad