#34949: Fails to create unique constraints
-------------------------------------+-------------------------------------
     Reporter:  Roman Odaisky        |                    Owner:  Jordan
                                     |  Bae
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Jordan Bae):

 Thanks for sharing ur thought. Currently I am trying to update two
 changes.
 when i check 4options related this issue with below code

 {{{
 class Ticket34949(models.Model):
     a = models.IntegerField()
     b = models.IntegerField()
     c = models.IntegerField()
     d = models.IntegerField()
     e = models.IntegerField()
     f = models.IntegerField()

     class Meta:
         constraints = [
             models.UniqueConstraint(fields=['a'], name='unique_a'),
             models.UniqueConstraint(fields=['b'], name='unique_b_c',
 include=['c']),
             models.UniqueConstraint(fields=['d'], name='unique_d_e',
 deferrable=models.Deferrable.DEFERRED),
             models.UniqueConstraint(fields=['e'], name='unique_e',
 nulls_distinct=False),
             models.UniqueConstraint(fields=['f'], name='unique_f',
 opclasses=['varchar_pattern_ops'])
         ]
 }}}

 Django makes only a,f unique constraints in MySQL.
 I think opclasses, include are option for optimization. so it needs to
 make unique constraints as David said.
 And nulls_distinct, deferrable are related to unique constraints behavior.
 so, Django shouldn't make unique constraints. so, my actions are below two
 items.
 1) fix includes
 2) update documents for distinguishing between opclasses, include and
 nulls_distinct, deferrable.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34949#comment:7>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018cecd9f3f8-0afabb2d-32d7-4259-bbdb-02dca7fd9a52-000000%40eu-central-1.amazonses.com.

Reply via email to