Migration issues #56319
Unanswered
ZabihSirat
asked this question in
Ideas
Migration issues
#56319
Replies: 2 comments
-
The filename is based on datetime. Just make sure the file that needs to be run first has an older date time... Or migrate both tables in one migration? There is no law that says you need to migrate one table per migration file. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This would mean a huge breaking change which is just not likely. But if you scale down your approach, you can add
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🧠 Problem
Developers often face migration errors due to foreign key dependencies when running php artisan migrate. Laravel relies on filename order for execution, but FK constraints require certain tables to be created first. This can cause confusion, especially in large teams or when writing modular migrations.
💡 Proposed Solution
Laravel should analyze migration files to detect foreign key dependencies, build a dependency graph, and determine the correct execution order dynamically. This would eliminate the need for manual filename ordering and reduce migration-related errors.
🔧 How It Might Work
Laravel scans all migration files (using static parsing)
Builds a Directed Acyclic Graph (DAG) of dependencies
Applies topological sort to determine execution order
Optional flag: php artisan migrate --smart
Optional config: 'auto_dependency_ordering' => true
🎯 Benefits
Better DX (Developer Experience)
Safer migrations across large codebases
Less need for migration file renaming or reordering
Easier to maintain modular, decoupled migrations
📦 Compatibility
This can be an optional feature, disabled by default to avoid breaking existing behavior.
🚀 Final Note
This feature would bring Laravel one step closer to intelligent automation — a true benefit for both new and advanced users.
Beta Was this translation helpful? Give feedback.
All reactions