Hello Pavel,

This is likely a bug because UniqueConstraint was only recently introduced.

Please file a bug report about it. In the mean time you can add this check 
to
your SILENCED_SYSTEM_CHECKS setting to silence it.

Best,
Simon

Le lundi 20 janvier 2020 07:21:26 UTC-5, Pavel Garkin a écrit :
>
> Hi all,
>
>
> I'm trying to create migration with uniqueness of 2 fields: uid, source. 
>
> *Django 2.2.9*
>
> 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 
> <https://docs.djangoproject.com/en/2.2/ref/checks/#related-fields>* 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 
> <https://docs.djangoproject.com/en/2.2/ref/models/options/#unique-together> 
> unique_together may be deprecated in the future so I wanted to avoid this 
> kind of issue.
>
>
>
> *Thanks,*
>
> *Pavel*
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b49b70d2-9a1d-409f-ac43-3a643a7f27b1%40googlegroups.com.

Reply via email to