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
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.
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.
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 .
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With