Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simplify migrations in Django 1.7?

There are already similar questions for South, but I have started my project with Django 1.7 and am not using South.

During development a lot of migrations have been created, however the software is not yet delievered and there exists no database that must be migrated. Therefore I would like to reset the migrations as if my current model was the original one and recreate all databases.

What is the recommended way to do that?

EDIT: As of Django 1.8 there is a new command named squashmigrations which more or less solves the problem described here.

like image 297
Kit Fisto Avatar asked May 20 '14 09:05

Kit Fisto


People also ask

Can I delete all migrations Django?

If you do not have any permanent databases, then yes, you can remove all migrations, run python manage.py makemigrations --initial and it will create fresh migrations based on your current models. Also, you should check if any of the migrations are custom data migrations written by hand.

What is difference between migrate and migration in Django?

So the difference between makemigrations and migrate is this: makemigrations auto generates migration files containing changes that need to be applied to the database, but doesn't actually change anyhting in your database. migrate will make the actual modifications to your database, based on the migration files.


2 Answers

I got this. I just figured this out and it is good.

  • First, to clear migrations table:

    ./manage.py migrate --fake <app-name> zero 
  • Remove app-name/migrations/ folder or contents.

  • Make the migrations:

    ./manage.py makemigrations <app-name> 
  • Finally tidy up your migrations without making other database changes:

    ./manage.py migrate --fake <app-name> 
like image 109
kzorro Avatar answered Sep 23 '22 11:09

kzorro


In the Django 1.7 version of migrations the reset functionality that used to be in South has been dropped in favor of new functionality for 'squashing' your migrations. This is supposed to be a good way to keep the number of migrations in check.

https://docs.djangoproject.com/en/dev/topics/migrations/#squashing-migrations

If you still want to really start from scratch i assume you still could by emptying the migrations table and removing the migrations after which you would run makemigrations again.

like image 43
tijs Avatar answered Sep 19 '22 11:09

tijs