📜  errno: 150 外键约束的格式不正确 laravel 8 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:34.646000             🧑  作者: Mango

代码示例1
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();