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.
- Drop the table ‘django_migrations’. If using mysql, the command is
DROP TABLE 'django_migrations';
- In every app (appname), delete all files in appname/migrations except for __init__.py
- Run
./manage.py makemigrations
. If using a custom user model (customuser), run./manage.py makemigrations customuser
&&
./manage.py makemigrations
Run ./manage.py migrate --fake
the ‘django_migrations’ table will be automatically created.
This code was last tested on django 3.2.5