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!
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__.pyand not themigrations/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-migrationsbranch -
Merge
reset-migrationsintomainandgit push
Assuming you want to deploy your main branch in production.
-
On your production server while on the
mainbranch, but not yet havinggit 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