Many tuples in unique_together

When I define a model and using unique_together in Meta, I can define more than one tuple. Will they be ORed or ANDed? This means that I have a model where

  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'))

either drugs or ounces are unique, or both are drunk, and quarts are unique, but not both.

+5
source share
1 answer

Each tuple creates a discrete UNIQUE in a CREATE TABLE . Thus, each tuple is independent, and the insertion will fail if the integrity constraint is violated.

+3
source

Source: https://habr.com/ru/post/1241551/


All Articles