Laravel migration: “Foreign key constraint is incorrectly formed” (errno 150)

后端 未结 22 895
有刺的猬
有刺的猬 2020-11-30 07:21

When migrating my DB, this error appears. Below is my code followed by the error that I am getting when trying to run the migration.

Code



        
22条回答
  •  再見小時候
    2020-11-30 08:04

    I got the same message for data type miss-matched problem.

    I used bigIncrements() for 'id' and when I used it as foreign key (used bigInteger()) I got the error.

    I have found the solution, bigIncrements() returns unsignedBigInteger. So need to use unsignedBigInteger() instead of bigInteger() in foreign key

    Sharing this because it might help others

提交回复
热议问题