Rolling back to a previous migration in django

19.9k views Asked by At

I used my django migrations to migrate my database. One of the migrations was data migrations. But I made a mistake: I didn't save the model). Thus, no change was applied to data. I corrected the .py file that executed the python code for the data migrations. I now want to re-execute it. Is there a way to rollback to the previous version of my database or just running

./manage.py migrate my_app 0004 

with 0004 being the file that did the datamigrations does the trick?

1

There are 1 answers

1
Apostolos On

In order to rollback I had to do the following

  1. showmigrations to see where I am
  2. migrate 0003 (to go one step back)
  3. showmigrations to verify that it worked and I am one version behind
  4. migrate 0004 to migrate correctly