Django migrations, friend or foe? Optimize your Django migrations for faster testing
summary
Django commands used: makemigrations, migrate, showmigrations, sqlmigrate, squashmigrations and migrate --prune; config knobs: KEEPDB and setting MIGRATE=False. Claim: hundreds of tiny migrations slow test DB creation (tests 1s, DB create ~20s → ~21s). Squashing alone keeps DB create ~20s. Recreating migrations from scratch yields DB create ~5s and total ~6s. Built a sample repo with branches, required manual porting for custom SQL/initial-data, and careful handling of circular dependencies and fixtures.
AI-written summary · about
chapters (10)
- 0:00Django migrations intro
- 3:58How migrations work
- 7:08Migration complexity in dev
- 10:25Performance issues with test database creation
- 12:15Faster test DB setup
- 13:58Squashing limits
- 17:55Squashing in Django 4.1
- 19:44Recreate migrations
- 23:22Optimization results
- 23:45Q&A
related talks
26mDjango migrations, friend or foe? Optimize them for testing
29mSecrets of the testing masters
25mWhat happens when you run manage.py test ?
26mDjango Unstrained
32mEasy, Breezy, Beautiful... Django Unit Tests with Colleen Dunlap
12mDjangoCon 2008 Keynote Questions: State of Django
30mUnderstanding migration development in Drupal 8: Strategies and tools to see what's happening
31mTricks and treats for new developers
