Unique constraint error with model inheritance while ModelForm should not validate
|Reported by:||fgaudin||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.1|
|Severity:||Keywords:||unique constraint, ModelForm, inheritance|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The use case is :
- ParentClass has an attribute "name" with unique=True
- FirstSubClass inherits ParentClass
- SecondSubClass inherits ParentClass
With a ModelForm for each subclass, I can't create two FirstSubClasses with the same name, neither two SecondSubClasses, the form doesn't validate, what is expected.
But if I create a FirstSubClass instance and try to create a SecondSubClass instance, the form validate and unique constraint error is raised by postgres.
A project showing the use case with unit tests is in attachment.
Change History (13)
comment:2 Changed 7 years ago by
|Component:||Forms → Database layer (models, ORM)|
|Triage Stage:||Unreviewed → Accepted|