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 __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

Discussion (1)

Collapse
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