How zero downtime migrations work and differ from standard Django
masterUnlike the standard Django backend, this backend does not use transactions for migrations (except for RunPython operations). This is because some SQL fixes cannot be run within a transaction, and avoiding transactions helps prevent deadlocks during complex migrations.
Implications:
- If a migration fails halfway, you must fix the database state manually.
- Best Practice: Keep migration modules as small as possible.
- Automation: Use
ZERO_DOWNTIME_MIGRATIONS_IDEMPOTENT_SQL=Trueto allow rerunning failed migrations after manual fixes. - Safety: It provides additional guarantees to avoid stuck table locks by using explicit timeouts and explicit constraint dropping.