#36357: inspectdb creates a redundant unique_together for composite primary keys
-------------------------------------+-------------------------------------
     Reporter:  Baptiste Mispelon    |                     Type:
                                     |  Cleanup/optimization
       Status:  new                  |                Component:  Database
                                     |  layer (models, ORM)
      Version:  5.2                  |                 Severity:  Normal
     Keywords:  CompositePrimaryKey  |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 With the following table:
 {{{#!sql
 CREATE TABLE example (
     a integer,
     b integer,
     c integer,
     PRIMARY KEY (a, c)
 );
 }}}

 Running `inspectdb` produces the following model definition:
 {{{#!py
 class Example(models.Model):
     pk = models.CompositePrimaryKey('a', 'c')
     a = models.IntegerField()
     b = models.IntegerField(blank=True, null=True)
     c = models.IntegerField()

     class Meta:
         managed = False
         db_table = 'example'
         unique_together = (('a', 'c'),)
 }}}

 I'm pretty sure the last `unique_together = (('a', 'c'),)` is redundant
 since the `pk = models.CompositePrimaryKey('a', 'c')` already implies
 uniqueness, no?
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36357>
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 visit 
https://groups.google.com/d/msgid/django-updates/010701967b4395e9-698ceb78-6dae-48ae-b0eb-4f85ff5d69e1-000000%40eu-central-1.amazonses.com.

Reply via email to