Multiple Migrations That Reference Each Other Not Migrating In Correct Order #10
Unanswered
danielheramb
asked this question in
Q&A
Replies: 1 comment
-
Currently I use option 1 for the small number of packages that need this. |
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.
-
Do you have a recommended solution for when a package has multiple migrations that need to be migrated in a specific order due to foreign key references? Currently, all migration files are prefixed with the same timestamp when published, which leads to them being run in the alphabetical order of the original migration filenames.
The best options I could come up with were:
EXAMPLE:
Cars Migration (references owners): database/migrations/create_cars_table.php.stub
Owners Migration: database/migrations/create_owners_table.php.stub
When published, they are renamed to:
database/migrations/2021_02_09_231731_create_cars_table.php
and
database/migrations/2021_02_09_231731_create_owners_table.php
meaning that artisan will attempt to migrate the cars table first since that file name is alphabetically before the other. This throws a QueryException since the owners table doesn't exist yet when referenced by the foreign key in cars
Beta Was this translation helpful? Give feedback.
All reactions