#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.