migrations

Django database migrations best practices

Migrations track database schema changes. I use makemigrations after model changes and review generated migrations. For data migrations, I create empty migrations with makemigrations --empty and write RunPython operations. I test migrations on dev dat

SQL migration safety: add column nullable, backfill, then constrain

The fastest way to surprise yourself in production is ADD COLUMN ... NOT NULL DEFAULT ... on a large table. My safe pattern is: add the column nullable with no default, backfill in batches, then add the NOT NULL constraint. If I need a default for new