For foreign key migrations instead of integer()
use unsignedInteger()
type or integer()->unsigned()
, otherwise you may get SQL errors.
1Schema::create('employees', function (Blueprint $table) {2 $table->unsignedInteger('company_id');3 $table->foreign('company_id')->references('id')->on('companies');4 // ...5});
You can also use unsignedBigInteger()
if that other column is bigInteger()
type.
1Schema::create('employees', function (Blueprint $table) {2 $table->unsignedBigInteger('company_id');3});