I have an orders table and a have a sell_shipping_labels
which references orders.id
as a foreign. However when I run the Laravel migration I get th
For laravel 6+ users, I agreed with the top 2 answers its all depends on laravel versions, For the latest versions users id
column uses big integer
. So referencing the users id
from current migration you need to use unsignedBigInteger
as a reference key.
Bellow is a migration example for laravel 6.5.*, Whenever we assign foreign key
Keep in mind of your current laravel version
Schema::create('galleries', function (Blueprint $table) {
$table->bigIncrements('id');
==>$table->unsignedBigInteger('user_id');
$table->string('title');
$table->string('description');
$table->timestamps();
==>$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});