Unable to have abstract model with unique_together
|Reported by:||mitar||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.3|
|Cc:||mmitar@…, segfault, direx||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I have such model definition:
class SlugVersion(models.Model): class Meta: abstract = True unique_together = (('slug', 'version'),) slug = models.CharField(db_index=True, max_length=10, editable=False) version = models.IntegerField(db_index=True, editable=False) class Base(SlugVersion): name = models.CharField(max_length=10) class Test(Base): test = models.IntegerField()
And I am getting:
Error: One or more models did not validate: test.test: "unique_together" refers to slug. This is not in the same model as the unique_together statement. test.test: "unique_together" refers to version. This is not in the same model as the unique_together statement.
I see this is as a bug. Why there could not be a table for class Base with unique constraints on its slug and version fields, and then 1-1 relationship with additional table for model Test with field test.
Change History (6)
comment:1 Changed 5 years ago by mitar
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset