Skip to content

Instantly share code, notes, and snippets.

@neoreids
Forked from repodevs/django_undo_migration.md
Created February 26, 2021 05:16
Show Gist options
  • Save neoreids/e923373fb7b0b02c139ba9d84e7cdfa9 to your computer and use it in GitHub Desktop.
Save neoreids/e923373fb7b0b02c139ba9d84e7cdfa9 to your computer and use it in GitHub Desktop.
How to undo migration in Django

Let say you have migrations like this

project/apps/accounts/migrations
├── 0001_initial.py
├── 0002_historicalprofile_historicaluser.py
├── 0003_auto_20190807_1559.py
├── 0004_auto_20190811_1013.py

and currently you are in 0004_auto_20190811_1013.py migrations. and you want to undo migration or back to previous migration which is 0003_auto_20190807_1559.py

Use this command:

$ python manage.py migration accounts 0003

Note: accounts is the django app

You will see the output like:

Operations to perform:
  Target specific migration: 0003_auto_20190807_1559, from accounts
Running migrations:
  Rendering model states... DONE
  Unapplying accounts.0004_auto_20190811_1013... OK

Your django database now in 0003_auto_20190807_1559.py migrations.

Whats next?

Remove your 0004_auto_20190811_1013.py file. and you can start make new migrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment