Resetting Django Migrations Without Losing Data

This shows how to reset django migrations without losing any data. If you’ve deleted an app, this is also a great way of resetting migrations to prevent future conflicts.

  1. Drop the table ‘django_migrations’. If using mysql, the command is DROP TABLE 'django_migrations';
  2. In every app (appname), delete all files in appname/migrations except for __init__.py
  3. Run ./manage.py makemigrations. If using a custom user model (customuser), run ./manage.py makemigrations customuser && ./manage.py makemigrations
  4. Run ./manage.py migrate --fake

the ‘django_migrations’ table will be automatically created.

This code was last tested on django 3.2.5

Leave a Reply

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