How to reset django migrations

Aditya Rawas - Feb 19 '21 - - Dev Community

Django migrations system is complex and optimal way to manage migrations, one can create, delete and update large number of models with ease, but this might sometime can create some unwanted trouble. If you are in development environment and will not mind cleaning up migrations here are few sets to follow.

1. Delete all migrations files in your project.

Navigate to migrations folder and delete all .py and .pyc files except __init__.py file
OR
Run following commands.

find . -path “*/migrations/*.py” -not -name “__init__.py” -delete
find . -path “*/migrations/*.pyc” -delete
Enter fullscreen mode Exit fullscreen mode

2. Delete/Drop your database, if you are using Sqlite simply delete db.sqlite3 file.

3. Run following commands to create new model and migrations files.

python manage.py makemigrations
python manage.py migrate
Enter fullscreen mode Exit fullscreen mode

And you are done these are few simple steps to reset migrations within your project.

Aditya Rawas Coffee

. . . . . . . . . . . . . . . . . . . . .
Terabox Video Player