“General error: 1005 Can’t create table” Using Laravel Schema Build and Foreign Keys

I’ve been having the same problem. I just noticed the following note at the very bottom of the Laravel Schema docs:

Note: The field referenced in the foreign key is very likely an auto increment and therefore automatically an unsigned integer. Please make sure to create the foreign key field with unsigned() as both fields have to be the exact same type, the engine on both tables has to be set to InnoDB, and the referenced table must be created before the table with the foreign key.

For me, as soon as I set my foreign key fields as such:

$table->integer('author')->unsigned();

I had no problem.

EDIT: Also, make sure that the fields in the foreign table are already created, otherwise this may fail with the same error.

Leave a Comment