Remove app with Django 1.7 migrations

diegopau picture diegopau · Feb 8, 2015 · Viewed 7.3k times · Source

I would like to know whats the cleanest way to remove all tables for a removed app using Django migrations. If for example I install a new package, I add the app to my settings.py and I do a manage.py makemigrations and a manage.py migrate; when then I decide that I don't want to use this package and I remove it from my settings.py, the command manage.py makemigrations will tell me "no changes detected" and so manage.py migrate will do nothing, but I need to remove the tables that this removed app had created.

I expected Django migrations to handle this so if I remove a app it would also create migrations to remove all the necesary tables.

Answer

ara.hayrabedian picture ara.hayrabedian · Dec 13, 2015

you'd have to be careful with this one, make sure you understand the operations being reversed when you do it, but something like this should work:

manage.py migrate <app_name> zero

obviously you have to do this before removing it from your settings and such so migrations are discoverable.

edit: this has slowly been receiving a few upvotes - I figured I'd direct everybody towards the appropriate documentation, in particular:

Use the name zero to unapply all migrations for an app.