In Django's migrations code, there's a squashmigrations
command which: "Squashes the migrations for app_label
up to and including migration_name
down into fewer migrations, if possible."
So, if you want to squash, say, the first 5 migrations, this will help.
What's the best way to squash starting with a particular migration_name
?
In a project I'm currently working on, we've added 5-10 new migration files as we've added new features. We'll deploy the whole project at once and it looks like running these individually will take too long. I'd like to squash all the migrations for this project into a single migration and test the time to run that.
python manage.py squashmigrations <appname> <squashfrom> <squashto>
python manage.py help squashmigrations
https://docs.djangoproject.com/en/dev/topics/migrations/#migration-squashing
This will give you more granular control over which migrations to squash, and let you keep a cleaner commit history. Deleting + recreating all migrations may cause other issues such as circular dependencies depending on how models are constructed.