Migration squashing combines several Django migration stages into one file. It reduces the work required when repeatedly creating new project instances from scratch, while preserving the migration history needed by existing instances. section 10.3
Think of it as replacing a long sequence of instructions with one bundled instruction. Django uses the squashed migration for new installations, while older migration files can remain temporarily so existing databases continue to recognize their history. section 10.3 section 10.6
A practical squashing workflow looks like this:
- Make and apply separate model changes, such as adding birth and death fields to the Promoter model. section 10.3
- Run squashmigrations with the app name and the starting and ending migrations: python manage.py squashmigrations promoters 0006 0007. section 10.3
- Commit the new migration and leave the originals in place until every deployed instance has applied the migrations being replaced. section 10.6
Promoter migration cleanup
After 0006_promoter_birth.py and 0007_promoter_death.py exist, Django creates 0006_promoter_birth_squashed_0007_promoter_death.py. The old files may remain during the transition; Django ignores them after the squashed migration replaces their dependency path.
