This is how I dealt with this problem. Keep in mind that I'm using PostGres as my database, and I don't know if the same problems occur with other databases (although I assume that they do).
Unique combinations can be applied to only one table or view in PostGres. This means that Django / Django-polymorphic cannot express unique database restrictions in the combination of fields found in both the parent table and the child table of Django models in the inheritance hierarchy.
If you really want the database to enforce unique restrictions on these fields, you can do one of these two things:
- copy all the fields of the parent model that participate in the unique constraint in the child table and express the unique constraint for the child fields and fields copied from the parent, or
- Create a view for the child that includes both the parent and child fields, and express a unique constraint in that view.
You will have to either do this manually or create your own structure to automatically insert / modify / delete these restrictions.
source share