我有关于我的种子的问题。这是我的表结构:
```html
请注意,保留了HTML标签。
现在我有种子:
我遇到了这样的问题/错误:
```html
...
```请注意,保留了HTML标签。
1.Complaints:
Schema::create('complaints', function (Blueprint $table) {
$table->uuid('id');
$table->unsignedInteger('origin_id');
$table->timestamps();
$table->primary('id');
});
2.Complaint_bill
Schema::create('complaint_bills', function (Blueprint $table) {
$table->uuid('complaint_id');
$table->string('symbol')->nullable();
$table->string('item_name');
$table->timestamps();
$table->primary('complaint_id');
$table->foreign('complaint_id')->references('id')-
>on('complaints');
现在我有种子:
factory(Complaint::class, 10)->create()->each(function ($c) {
$product = Product::inRandomOrder()->first();
factory(ComplaintBill::class, 10)->create([
'complaint_id' => $c->id,
'item_id' => $product->id,
'item_name' => $product->name,
'item_numeric_index' => $product->numeric_index,
'item_gross_price' => $product->sell_price_gross,
]);
})'
我遇到了这样的问题/错误:
SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value
violates u
nique constraint "complaint_bills_pkey"
DETAIL: Key (complaint_id)=(ea302ab8-67dc-3bed-afc8-4215a99f1f68)
already exists.
当我在Complaint_bill(列 - complaint_id)中评论主键时,一切正常。看起来问题在于我在Complaint_bill上有一个uuid的主键,而这个uuid是Complaint->id的外键。为什么会这样做呢?当我有两个主键关系时,我不能在外键上设置主键吗?