#31650 closed Cleanup/optimization (fixed)
Mention uniqueness of constraint names in the "name" attribute docs.
Reported by: | Hanne Moa | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | Documentation | Version: | 3.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
When using unique_together
, Django will create a unique name for you.
What I have seen with inexperienced people using Django 2.2 and newer is that when they use UniqueConstraint
instead of unique_together
they build up a name from the fields involved and maybe the word "unique". So, when they have two different models with the same fields needing to be in a unique constraint, they end up with the same name, and hence sooner or later an error.
It should be mentioned in the documentation whenever *Constraint.name is mentioned that the name needs to be unique for the database, and for 3.0 the example should be updated to include %(app_label)s
or at a minimum %(class)s
.
Change History (5)
comment:1 by , 5 years ago
Easy pickings: | set |
---|---|
Summary: | Documentation does not mention that constraint names must be unique per database → Mention uniqueness of constraint names in the "name" attribute docs. |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
It's mentioned in "Constraints in abstract base classes" admonition. Moreover there is a system check for uniqueness of constraints names, see #30396. Nevertheless, I think we can add it also to the
CheckConstraint.name
andUniqueConstraint.name
docs, e.g. "You must always specify a unique name for the constraint.".I don't agree, you don't need interpolation in most of cases.