当我迁移数据库时,出现此错误。下面是我的编码:
代码:
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('category_id')->nullable();
$table->string('name');
$table->text('description')->nullable();
$table->boolean('active')->default(1)->nullable();
$table->double('code');
$table->integer('unit')->default(1);
$table->string('image')->nullable();
$table->double('price');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('category_id')->references('id')->on('categories');
});
}
错误:
Illuminate \ Database \ QueryException:SQLSTATE [HY000]:常规错误:1005无法创建表
reochi
。products
(错误号:150“外键约束格式不正确”)(SQL:更改表products
添加约束products_category_id_foreign
外键(category_id
)引用categories
(id
))