#31185: UniqueConstraint rises fields.E310 error because of issue with no 
backward
compatibility with unique_together
-------------------------------------+-------------------------------------
               Reporter:  Pavel      |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:             |        Version:  2.2
  Migrations                         |       Keywords:  UniqueConstraint,
               Severity:  Normal     |  unique_together
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Hello,

 I'm trying to create migration with this kind of model.

 {{{
 class AppUsers(models.Model):
     name = models.CharField(...)
     uid = models.CharField(...)
     source = models.ForeignKey(...)

     class Meta:
         constraints = [models.UniqueConstraint(fields=['uid', 'source'],
 name='appusers_uniqueness')]
 }}}

 When I start ''makemigrations'' command in manage.py I've faced
 fields.E310 [https://docs.djangoproject.com/en/2.2/ref/checks/#related-
 fields] error

 It says that I should add unique_together field in Meta options:
 **app_name.AppUsers.field: (fields.E310) No subset of the fields 'uid',
 'source' on model 'AppUsers' is unique.
 HINT: Add unique=True on any of those fields or add at least a subset of
 them to a unique_together constraint.**

 If I change Meta options to unique_together constraint migration passes
 with no errors.


 {{{
 class AppUsers(models.Model):
     name = models.CharField(...)
     uid = models.CharField(...)
     source = models.ForeignKey(...)

     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 think
 nobody wants to face this issue when this will be deprecated :)

 Thanks,
 Pavel

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31185>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.651fd86abc13af1f6ad544b301dd6304%40djangoproject.com.

Reply via email to