class Users(models.Model):
uid = models.CharField(...)
source = models.ForeignKey(...)
class Meta:
constraints = [models.UniqueConstraint(fields=['uid', 'source'], name='users_uniqueness')]
indexes = [models.Index(fields=('uid', 'source'), name='users_indexes')]
When I start makemigrations command in manage.py it rises fields.E310 error
app_name.Users.field: (fields.E310) No subset of the fields 'uid', 'source' on model 'Users' is unique.
HINT: Add unique=True on any of those fields or add at least a subset of them to a unique_together constraint.
When I change Meta options to unique_together constraint it works ok. Migrations passes with no errors
...
class Meta:
unique_together = [['uid', 'source']]
As mentioned in docs unique_together may be deprecated in the future so I wanted to avoid this kind of issue.
Thanks,
Pavel