Sunday, February 13, 2022

[FIXED] Laravel migration problem : Foreign key constraint is incorrectly formed in l

Issue

I make the same data type for both of that table but there is a problem. But for another table I didn't get any error. what is the problem behind? enter image description here enter image description here General error: 1005 Can't create table meal_system.amounts (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table amounts add constraint amounts_member_id_foreign foreign key (member_id) references members (member_id) on delete cascade)


Solution

You need first to migrate members before amounts table case your foreign is with member_id to migrate members first just change the date of the migration file to be before the amount

For example :

2021_01_01_000000_create_members_table

2021_02_02_100000_create_amounts_table


Answered By - Wael Khalifa

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.