Skip to content
Advertisement

Laravel migration file 2 foreign keys can not be created

I am trying to create a new table where 2 foreign key will be set

JavaScript

I keep getting an error saying

JavaScript

I have tried moving the code around and some online solutions but keep getting the same error.

permission migration file

JavaScript

users_role migration file

JavaScript

Advertisement

Answer

Solution 1 – Data Types ~(Not this time!)~~

Something to check would be that the datatypes of your columns and keys match.

It is not uncommon to see this error if the foreign key (i.e. $table->integer('permissions_id')->unsigned();) on one table does not match the id on the other table ($table->bigIncrements('id');)


Solution 2 – Migration Order (Correct)

permissions should be before role_permissions. You may need to rename the migrations slightly as they will run in date order based off of their names.

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