gpt4 book ai didi

python - unique_together 中的多个元组

转载 作者:太空狗 更新时间:2023-10-29 17:31:53 29 4
gpt4 key购买 nike

当我定义一个模型并在 Meta 中使用 unique_together 时,我可以定义多个元组。这些是要进行 OR 运算还是 AND 运算?也就是说,我有一个模型,其中

class MyModel(models.Model):    druggie = ForeignKey('druggie', null=True)    drunk = ForeignKey('drunk', null=True)    quarts = IntegerField(null=True)    ounces = IntegerField(null=True)    class Meta:        unique_together = (('drunk', 'quarts'),                           ('druggie', 'ounces'))

druggie 和 ounces 要么都是独一无二的,要么 drunk 和 quarts 都是独一无二的,但不是两者都是。

最佳答案

每个元组都会导致一个离散的 UNIQUE 子句被添加到 CREATE TABLE 查询中。因此,每个元组都是独立的,如果违反任何数据完整性约束,插入将失败。

关于python - unique_together 中的多个元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35024007/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com