ChatGPT解决这个技术问题 Extra ChatGPT

How to migrate back from initial migration in Django 1.7?

I created a new app with some models and now I noticed that some of the models are poorly thought out. As I haven't committed the code the sensible thing would be to migrate the database to last good state and redo the migration with better models. In this case the last good state is database where the new app doesn't exist.

How can I migrate back from initial migration in Django 1.7?

In South one could do:

python manage.py migrate <app> zero

Which would clear <app> from migration history and drop all tables of <app>.

How to do this with Django 1.7 migrations?


s
supervacuo

You can do the same with Django 1.7+ also:

python manage.py migrate <app> zero

This clears <app> from migration history and drops all tables of <app>

See django docs for more info.


Is this documented anywhere? The django documentation on migrations is severely lacking...
Doc can be found in the django-admin and manage.py documentation page: docs.djangoproject.com/en/1.7/ref/django-admin/…
@n__o Thanks. Updated answer.
How would you handle IntegrityError: NOT NULL constraint failed?
Just tried this on Django 1.9 and it worked fine as well. Thanks
C
Community

you can also use the version number:

python manage.py migrate <app> 0002

Source: https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-migrate


The question asked is about migrating back from the initial migration, and using 0000 does not work
i see, i may have misunderstood the question (although it's not particularly well written IMHO). why wouldn't you just drop the DB? oh well
dropping the whole DB for one table is a bit overkill