【发布时间】:2021-05-06 14:09:51
【问题描述】:
我对 Laravel 的 uuid 外键有一些问题。 我创建了如下表:
Schema::create('product_attributes', function (Blueprint $table) {
$table->uuid('id');
$table->string('label');
$table->integer('default_order')->nullable();
$table->timestamps();
});
Schema::create('product_attributes_value', function (Blueprint $table) {
$table->uuid('id');
$table->unsignedBigInteger('attribute_id');
$table->string('value');
$table->integer('default_order')->nullable();
$table->foreign('attribute_id')->references('id')->on('product_attributes');
$table->timestamps();
});
它总是给予
SQLSTATE[HY000]:一般错误:1005 无法创建表
ecommerce.product_attributes_value(errno: 150 "外键 约束格式不正确”)(SQL:alter tableproduct_attributes_value添加约束product_attributes_value_attribute_id_foreign外键 (attribute_id) 引用product_attributes(id))
我看不出有问题,可以吗?
【问题讨论】:
-
$table->unsignedBigInteger('attribute_id');到$table->uuid('attribute_id');两个数据类型应该相同