Django Migrations ↔ RunPython: Can Reverse Migrations Be Auto‑Generated?
0 reputation · 10 Sept 2025, 10:58 UTC
Django Migrations and RunPython: Rollback Safety
The goal is to guarantee that a schema change accompanied by a data migration can be rolled back without manual intervention. In practice, Django auto‑generates reversible schema operations but requires explicit reverse code for RunPython actions.
Key constraints include the lack of automatic reverse logic for data migrations and the need to mark a migration as irreversible to avoid accidental data loss. Uncertainty remains whether future releases might introduce automatic reverse generation or alternative mechanisms.
Specific questions for the community:
- Does Django currently support auto‑generation of reverse code for
RunPythonoperations? - What best practices or flags exist to declare a migration reversible when custom data logic is involved?
- How does the
reversibleflag influence migration planning and deployment pipelines?