我正在努力使ListField
ReferenceField
唯一,但我不应该得到一个独特的错误。这是为什么?
class Training(Document):
transactions = ListField(ReferenceField(Buy, reverse_delete_rule=PULL), default=list, unique=True)
b = Buy()
b.save()
b1 = Buy()
b1.save()
b2 = Buy()
b2.save()
# both should save fine since the lists are different
Training(transactions=[b, b1]).save()
Training(transactions=[b, b2]).save()
NotUniqueError:尝试保存重复的唯一键(E11000重复键错误集合:test_db.training index:transactions_1 dup key:{:ObjectId('575d33eceefe54280475fc1b')})