Skip to content
Advertisement

laravel errno 150 foreign key constraint is incorrectly formed

Can anybody help me to solve this problem?

There are 3 tables with 2 foreign keys:

JavaScript

Error after running migration:

JavaScript

Advertisement

Answer

In case of foreign keys, the referenced and referencing fields must have exactly the same data type.

You create the id fields in both users and firms as signed integers. However, you create both foreign keys as unsigned integers, therefore the creation of the keys fail.

You need to either add the unsigned clause to the id field definitions, or remove the unsigned clause from the foreign key fields.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement