Laravel migration (errno: 150 "Foreign key constraint is incorrectly formed")
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');
Since increments()
creates an unsigned integer column, you need to define the foreign key column as unsigned integer too.
Default migrations in Laravel 6+ use bigIncrements()
, so you need to use unsignedBigInteger()
method:
$table->unsignedBigInteger('order_id');
https://laravel.com/docs/6.x/migrations#foreign-key-constraints
For default migrations in older versions of Laravel use unsignedInteger()
method:
$table->unsignedInteger('order_id');
Or:
$table->integer('order_id')->unsigned();
https://laravel.com/docs/5.5/migrations#foreign-key-constraints