142

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?

Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
Seppo Erviälä
  • 7,160
  • 7
  • 35
  • 40
  • This is a case of you should have tried the command you wrote here. The answer and comment in it is pretty much a copy of this. – Akaisteph7 Aug 10 '23 at 14:22

2 Answers2

253

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.

supervacuo
  • 9,072
  • 2
  • 44
  • 61
Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
7

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

Community
  • 1
  • 1
jsh
  • 1,995
  • 18
  • 28