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
the foreign key must be an "unsignedBigInteger" and it will be fixed, something like this:
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
I had the same problem and fixed the issue setting the database type to innoDB
The tables created before the migration where 'MyISAM from an legacy system and the migrated are innoDB
by default, so the mix of table types were an issue in my case.
To anyone looking at this using laravel 5.8.x I fixed this by changing this
$table->unsignedInteger('foreign_id');
to this
$table->unsignedBigInteger('foreign_id');
That's due to the use of bigIncrements. You could instead remove chance bigIncrements to increments on both sides of the relation
I faced this problem today. I checked all of suggested solutions such as referenced key and foreign key same datatype, same collation in database engine and laravel config (database.php), date order of migrations and other possibility mistakes, but anyone were my solution! last thing I found was onUpdate and onDelete constraints that put in migrations. By removing them my problem solved!
Laravel 5.8.3 comes with
$table->bigIncrements('id');
change it to
$table->increments('id');
$table->integer('order_id')->unsigned();
Check the order of your migrations. If your migrate command is trying to make the sell_shipping_labels table before the orders table this will occur with MySQL. It seems to go on create migration date, oldest to newest. In other words, the order_id on the table it is trying to reference should exist.
I have faced the same problem and I change create migration date.