137

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?

2 Answers 2

244

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.

7
  • 7
    Is this documented anywhere? The django documentation on migrations is severely lacking...
    – rnevius
    Mar 25, 2015 at 10:57
  • 2
    Doc can be found in the django-admin and manage.py documentation page: docs.djangoproject.com/en/1.7/ref/django-admin/…
    – n__o
    Jul 31, 2015 at 5:50
  • @n__o Thanks. Updated answer. Jul 31, 2015 at 6:11
  • 1
    How would you handle IntegrityError: NOT NULL constraint failed?
    – wasabigeek
    Aug 26, 2015 at 15:23
  • 2
    Just tried this on Django 1.9 and it worked fine as well. Thanks
    – Dário
    Jul 22, 2016 at 12:39
8

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

3
  • 9
    The question asked is about migrating back from the initial migration, and using 0000 does not work Dec 22, 2017 at 9:39
  • 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
    – jsh
    Feb 22, 2018 at 22:02
  • 5
    dropping the whole DB for one table is a bit overkill Feb 23, 2018 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.