【发布时间】:2020-01-10 09:17:22
【问题描述】:
我在数据库中有一行:
order_id: product_type_id: is_child: child_type_id:
1 2 True 3
我想用这段代码添加一行:
订单 = 1,
product.parent = 2
order_item = OrderItem.objects.create(order=order, product_type=product.parent,
child_type_id=None, is_child=False)
但它会引发此错误:
django.db.utils.IntegrityError:重复键值违反唯一约束“order_orderitem_order_id_product_type_id_ee5c1733_uniq” DETAIL: Key (order_id, product_type_id)=(1, 2) 已经存在。
虽然 4 行中有 2 行不同,但为什么我会遇到这个问题?
【问题讨论】: