DEV Community

Aditya Rawas
Aditya Rawas

Posted on • Updated on

How to reset django migrations

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 file
Run following commands.

find . -path “*/migrations/*.py” -not -name “” -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 makemigrations
python 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

Top comments (1)

artu_hnrq profile image
Arthur Henrique

Hey Aditya! Nice share!
find can be a great option, however it won't work fully properly in multi-repository projects. I take the opportunity to leave a good alternative django-reset-migrations and link a discution