Error on migration by MySql 8 DB
Hello, First of all wave is amazing, however I have some issues if I try to use mysql istead of sqlite. First if all I'm getting the following error, as the table plans does not exists when the subscriptions table is beeing created:
SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'plans' (Connection: mysql, SQL: alter table `subscriptions` add constraint `subscriptions_plan_id_foreign` foreign key (`plan_id`) references `plans` (`id`) on delete cascade)
This is managable if I change the order and setting plans before subscriptions BUT if I do so, I'm getting the next error:
SQLSTATE[HY000]: General error: 3780 Referencing column 'plan_id' and referenced column 'id' in foreign key constraint 'subscriptions_plan_id_foreign' are incompatible. (Connection: mysql, SQL: alter table `subscriptions` add constraint `subscriptions_plan_id_foreign` foreign key (`plan_id`) references `plans` (`id`) on delete cascade)
Please assist how to manage this issue. Thank you! Cheers, Gabor
UPDATE:
I managed to solve the issue as follows:
- Change the order of plans and subscriptions table
- Change the datatype if the plan id on plans table to
$table->unsignedBigInteger('id')->primary();
- In
subscriptions
table comment out the following line$table->unsignedBigInteger('plan_id');
- Modify the last line
$table->foreign('plan_id')->references('id')->on('plans')->onDelete('cascade');
TO$table->foreignId('plan_id')->references('id')->on('plans')->onDelete('cascade');
SIDENOTE: This is only for the migration issue, I was not able to test in the app yet.
Cheers, Gabor
Hey!
Ah yes, we have a PR from a community member that patches that problem.
You can cherry pick the change from here:
We will be merging this soon as well!
- Bobby















