Saturday 13 August 2016

How to reset all migrations in django > 1.7 in windows and linux?

Django has a awesome way to handle changes in the database, which help us to track the structure of the database and keep us safe from manual interactions with the database. Databases changes are mapped according to the model definitions. If you worked in other python frameworks like Odoo or web2py then you can definitely realize what a great thing it is. Here is how they are defining these migrations:
Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema
But often times this facility becomes tension and we stuck in such a situation where it fails to caters our need and the only way we have is to reset all the migrations and start the migration from the initial. For such a situation in Windows and Linux these may can help you.

For Windows:

del project_dir/app_dir/migrations/*
echo.>project_dir/app_dir/migrations/__init__.py
python manage.py makemigrations
python manage.py migrate



For Linux :

$/home/project-dir@user: find . -path *migrations* -name "*.py" -not -path "*__init__*"
python manage.py makemigrations
python manage.py migrate


ref: http://stackoverflow.com/a/30016412/3832653

No comments:

Post a Comment

Note: only a member of this blog may post a comment.