Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge multiple django south migrations into one migration

Tags:

django-south

We use south to manage migrations for a long time, and now we have about 100+ migrations.

It caused a long time to run python manage.py migrate on a fresh db.

I'm wonder that whether I can merge all existing migrations to a single one migration

like image 301
Quanlong Avatar asked Jul 25 '14 09:07

Quanlong


People also ask

What is difference between migration and migrate in Django?

You should think of migrations as a version control system for your database schema. makemigrations is responsible for packaging up your model changes into individual migration files - analogous to commits - and migrate is responsible for applying those to your database.

How do I fix migration issues in Django?

you can either: temporarily remove your migration, execute python manage.py migrate, add again your migration and re-execute python manage.py migrate. Use this case if the migrations refer to different models and you want different migration files for each one of them.

How do I recreate all migrations in Django?

Django's migration can be reset by cleaning all the migration files except __init__.py files under each project app directory, followed by dropping the database and creating migration again using python manage.py makemigrations and python manage.py migrate .


2 Answers

This has been solved in Django 1.7 + There is a new management command ./manage.py squashmigrations appname , check this link - https://docs.djangoproject.com/en/1.7/topics/migrations/#squashing-migrations

like image 111
Njogu Mbau Avatar answered Nov 13 '22 07:11

Njogu Mbau


You can use the squashmigrations management command to get there. It'll leave the old migration files in place, yet use the squashed version when installing something new.

Example:

./manage.py squashmigrations core 0003_auto

See official docs

If you're looking to get rid of all the trial and error waste produced during development, remove the migrations from your apps migrations directory along with all mentions of your app in the SQL table django_migrations and the apps actual database tables.

Afterwards run ./manage.py makemigrations and you're good got go. This is not recommended for apps which are already in productive use.

like image 29
rgeber Avatar answered Nov 13 '22 07:11

rgeber