Blog

In this article we will discuss the ways to unapply migrations in django.

At this stage you know how to make changes to your database schema by creating and applying migrations. At some point, you might want to undo changes and switch back to an earlier database schema because you:

  • Want to test a migration a colleague wrote
  • Realize that a change you made was a bad idea
  • Work on multiple features with different database changes in parallel
  • Want to restore a backup that was created when the database still had an older schema

Luckily, migrations don’t have to be a one-way street. In many cases, the effects of a migration can be undone by unapplying a migration. To unapply a migration, you have to call migrate with the name of the app and the name of the migration before the migration you want to unapply.


$ python manage.py migrate productprice 0001_initial
Operations to perform:
  Target specific migration: 0001_initial, from productprice
Running migrations:
  Rendering model states... DONE
  Unapplying productprice.0002_auto_20181112_1950... OK

Unapplying a migration does not remove its migration file. The next time you run the migrate command, the migration will be applied again.

Leave a Reply

Your email address will not be published. Required fields are marked *