How to Revert Migration in Django?


You cannot revert a migration in Django but can migrate to a previous migration to apply the old changes on the database.

For example, consider the following as the last two migrations of the my_app Django app:

  1. 0009_previous_migration
  2. 0010_migration_to_revert

If for some reason you want to undo the last migration (i.e. 0010_migration_to_revert), you can re-migrate to the previous migration using the following command:

./ migrate my_app 0009_previous_migration

After migratiing to the previous migration, you can now delete migration ‘0010_migration_to_revert‘.

You can also reverse all migrations for an app. To do so, use zero inplace of the migration name.

./ migrate my_app zero

How to see old migrations of a Django app?

Using the following command you can list all migrations of my_app Django app.

./ showmigrations my_app

Leave a Reply

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