[Django] #34491: Unable to have constraints with same name on different models

32 views
Skip to first unread message

Django

unread,
Apr 13, 2023, 5:50:56 PM4/13/23
to django-...@googlegroups.com
#34491: Unable to have constraints with same name on different models
------------------------------------------------+------------------------
Reporter: Matheus Cansian | Owner: nobody
Type: Bug | Status: new
Component: Core (System checks) | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
PR 11278 (ticket #30396) added system checks to enforce uniqueness of
indexes and constraints names. The issue is that (at least for PostgreSQL)
the check is too strict. The namespace for table constraints (such as
CHECK, UNIQUE, FK) is the table itself. This means that you could have the
same name for a constraint if they are on different tables. Unfortunately,
this system check prevents you for doing that, forcing you to add the
unnecessary ''%(app_label)s_%(class)s'' to every constraint name.

Considering two models (ModelA and ModelB) both with one CheckConstraint
with the same name "test_constraint". The system check would return the
following error:

{{{
?: (models.E032) constraint name 'test_constraint' is not unique among
models: app.ModelA, app.ModelB.
}}}


https://github.com/django/django/pull/11278

--
Ticket URL: <https://code.djangoproject.com/ticket/34491>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 14, 2023, 4:56:28 AM4/14/23
to django-...@googlegroups.com
#34491: Unable to have constraints with same name on different models
-------------------------------------+-------------------------------------

Reporter: Matheus Cansian | Owner: nobody
Type: Bug | Status: closed
Component: Core (System | Version: 4.2
checks) |
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Simon Charette (added)
* status: new => closed
* resolution: => wontfix


Comment:

Thanks for the report. It's true that constraints on different tables may
have the same names on PostgreSQL. However, it's not truth on other
databases. Moreover, using the same names is a rare practice when we take
into account that it has not been noticed for 4 years. I'd prefer to keep
the check for cross-database compatibility. You can always silence it by
adding `SILENCED_SYSTEM_CHECKS = ["models.E032"]` to the settings.

I hope that makes sense.

--
Ticket URL: <https://code.djangoproject.com/ticket/34491#comment:1>

Reply all
Reply to author
Forward
0 new messages