19👍
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.
3👍
First, comment out all the classes in your app’s models.py. Then, create a new migration as you normally would, which will delete all the app’s tables, and run it. Finally, remove the entire app and all references to it from your code base.
- Django, division between two annotate result won't calculate correctly
- How to use forms in django-cms?
- How to add 'collapse' to a Django StackedInline
3👍
extending nachouve’s answer to a proper django migration, you can use a RunSQL
migration with all the DROP statements
, see the django migration docs.
You can either put this in the app your about to delete or (if you’ve already deleted the app or it’s installed so you can’t edit it) in a different app.
For example to clean up after deleting django-user-accounts (which has poor coverage and is a liability):
from django.db import migrations
DROP_ACCOUNT_TABLES = """\
DROP TABLE IF EXISTS account_account CASCADE;
DROP TABLE IF EXISTS account_accountdeletion CASCADE;
DROP TABLE IF EXISTS account_emailaddress CASCADE;
DROP TABLE IF EXISTS account_emailconfirmation CASCADE;
DROP TABLE IF EXISTS account_signupcode CASCADE;
DROP TABLE IF EXISTS account_signupcoderesult CASCADE;
"""
class Migration(migrations.Migration):
dependencies = [
('auth', '<< previous migations >>'),
]
operations = [
migrations.RunSQL(DROP_ACCOUNT_TABLES)
]
- How do I reply to an email using the Python imaplib and include the original message?
- Stop nosetests from printing logging information?
- How to use bower package manager in Django App?
- Whats the best way to duplicate data in a django template?