Description:
Hello Django Team,
First, thank you for the incredible work on Django — it has empowered many projects over the years.
I would like to suggest a new built-in feature or an official tool to help solve the common and complex migration issues that arise in long-term projects with numerous migrations across multiple apps.
Problem:
In large projects developed over years, the number of migration files can grow extensively (sometimes hundreds or even thousands). This often causes problems like:
- Broken migration dependencies across apps
- Conflicts when deleting or squashing migrations
- Difficulty resetting migrations cleanly without losing database consistency
- Challenges onboarding new environments where running all migrations sequentially is time-consuming
Proposed Solution:
A tool or built-in management command that can:
- Read the current state of all applied migrations directly from the database (
django_migrations
table). - Safely delete or archive all existing migration files from all apps in the project.
- Inspect the current database schema and introspect models from the codebase.
- Automatically generate a new initial migration file for each app that accurately represents the current database schema and the model definitions.
- Sync Django’s migration history state with this new baseline, so migrations continue smoothly going forward.
This would act like a “migration reset and sync” operation and help developers safely restart migrations on a clean slate without data loss or migration conflicts.
Benefits:
- Simplifies long-term maintenance of migrations in large projects
- Reduces migration-related bugs and dependency errors
- Improves onboarding experience by enabling a fresh migration baseline on existing databases
- Encourages best practices by automating a complicated manual process
I believe this could be a valuable addition to Django’s migration framework, improving developer productivity and project stability.
Thank you for considering this feature request!