Skip to content

Instantly share code, notes, and snippets.

@repodevs
Created February 2, 2020 18:45
Show Gist options
  • Save repodevs/414773bfab7aa6e8c998c0f54d1d47d5 to your computer and use it in GitHub Desktop.
Save repodevs/414773bfab7aa6e8c998c0f54d1d47d5 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.

@KeremKarsiyaka
Copy link

CommandError: No installed app with label 'accounts'.

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