PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 13, 2022

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

 February 13, 2022     laravel, laravel-8, mysql, php     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing