Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migration sequence to accomodate ->constrained() migration #4

Merged
merged 1 commit into from Aug 22, 2021

Conversation

vincentkedison
Copy link

Hello @bastinald,

Thanks a lot for this awesome package.
I'm Vincent from Indonesia, I recently explored your laravel-livewire-ui package.
However I found a problem whenever I create migration for a table that has a foreign to other tables. An error would occurred because the migration of related table run before the foreign table exist:

SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `table_products` add constraint `table_products_category_id_foreign` foreign key (`category_id`) references `id` (`categories`))

I tried to make some modification by sorting the model files using defined $migration_sequence variable. Using this variable, we can defined the migration running sequence.

If you think this is a good solution, you can freely accept this PR.

Thanks.

@bastinald
Copy link
Owner

Hey, this is a good idea, but one thing is that migration files are run before the automatic migrations.

The sequence would not accomodate for this, right? Also, are you coupling all your DB tables with models? Or using a mixture of files and models?

@bastinald
Copy link
Owner

I'm gonna merge and tweak this, I think it's a good idea regardless.

@bastinald bastinald merged commit 5fc779f into bastinald:master Aug 22, 2021
@bastinald
Copy link
Owner

This has been released under v 2.4.0. Only thing was I changed it to migrationOrder, hope that is ok.

Added info to readme here: https://github.com/bastinald/laravel-automatic-migrations#migration-order

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants