Skip to content

Instantly share code, notes, and snippets.

@cb109
Last active November 12, 2025 10:02
Show Gist options
  • Save cb109/a6671aba993cf914c2e2fb01a2309dc4 to your computer and use it in GitHub Desktop.
Save cb109/a6671aba993cf914c2e2fb01a2309dc4 to your computer and use it in GitHub Desktop.
Hard-reset all Django migrations

Based on Scenario 2 from: https://simpleisbetterthancomplex.com/tutorial/2016/07/26/how-to-reset-migrations.html

Note: This is different to squashing migrations and a potential destructive operation if done wrong!

Preparation

On your local development machine, with the current database schema:

  • Prepare a git branch

    git checkout -b reset-migrations
    
  • Reset the migration history for the app(s)

    python manage.py migrate --fake my_app zero
    python manage.py migrate --fake my_other_app zero
    
  • Delete all migration files from the app(s) you want to reset, but not the __init__.py and not the migrations/ folder itself:

    find . -path "my_app/migrations/*.py" -not -name "__init__.py" -delete
    find . -path "my_app/migrations/*.pyc"  -delete
    
    find . -path "my_other_app/migrations/*.py" -not -name "__init__.py" -delete
    find . -path "my_other_app/migrations/*.pyc"  -delete
    
  • Create the new initial migration file(s)

    python manage.py makemigrations
    
  • Commit all changes to the current reset-migrations branch

  • Merge reset-migrations into main and git push

Deployment

Assuming you want to deploy your main branch in production.

  • On your production server while on the main branch, but not yet having git pulled the latest changes, run these commands:

    python manage.py migrate --fake my_app zero
    python manage.py migrate --fake my_other_app zero
    
    git pull
    
    python manage.py migrate --fake-initial
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment