[Django] #34423: Migrations, UniqueConstraint lenght of identifier can be too long for Postgres/MySQL

10 views
Skip to first unread message

Django

unread,
Mar 20, 2023, 4:10:22 AM3/20/23
to django-...@googlegroups.com
#34423: Migrations, UniqueConstraint lenght of identifier can be too long for
Postgres/MySQL
-------------------------------------+-------------------------------------
Reporter: joelbitar | Owner: nobody
Type: Bug | Status: new
Component: | Version: 4.1
Migrations | Keywords: migrations,
Severity: Normal | unique_constraint, UniqeConstraint
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When creating a new unique constraint it is quite easy with the
interpolation of %(class)s to generate a very long name as identifier
(name) of the constraint.

Postgres and MySQL both have limits on how long the name can be (63/64)
characters, Postgres does allow for a longer name but it will be
truncated.

Creating two names with the same first part will make it so that we have
two identical identifiers and the migrations will not work.

An error like this will be thrown;


{{{
django.db.utils.ProgrammingError: relation
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" already
exists
}}}

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

Django

unread,
Mar 20, 2023, 4:21:49 AM3/20/23
to django-...@googlegroups.com
#34423: Migrations, UniqueConstraint lenght of identifier can be too long for
Postgres/MySQL
-------------------------------------+-------------------------------------
Reporter: joelbitar | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.1
Severity: Normal | Resolution:
Keywords: migrations, | Triage Stage:
unique_constraint, | Unreviewed
UniqeConstraint |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by joelbitar):

PR; https://github.com/django/django/pull/16664

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

Django

unread,
Mar 20, 2023, 5:03:04 AM3/20/23
to django-...@googlegroups.com
#34423: Migrations, UniqueConstraint lenght of identifier can be too long for
Postgres/MySQL
-------------------------------------+-------------------------------------
Reporter: Joel Shapiro | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Migrations | Version: 4.1
Severity: Normal | Resolution: wontfix

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

* status: new => closed
* type: Bug => Cleanup/optimization
* resolution: => wontfix


Comment:

Thanks for this ticket, however, I'm against this change. First of all it
is backward incompatible. Constraints have been introduced in Django 2.2
and constraints with a name of length greater than 63 characters are valid
on other databases (64 on MySQL, 128 on MSSQL, etc.). I agree that it is a
inconsistency between constraints and indexes policy but still we need to
be careful with introducing incompatibilities. See also a related ticket,
#30614.

Please first start a discussion on the DevelopersMailingList, where you'll
reach a wider audience and see what other think, and
[https://docs.djangoproject.com/en/stable/internals/contributing/triaging-
tickets/#closing-tickets follow the triaging guidelines with regards to
wontfix tickets].

--
Ticket URL: <https://code.djangoproject.com/ticket/34423#comment:2>

Django

unread,
Mar 20, 2023, 5:59:49 AM3/20/23
to django-...@googlegroups.com
#34423: Migrations, UniqueConstraint lenght of identifier can be too long for
Postgres/MySQL
-------------------------------------+-------------------------------------
Reporter: Joel Shapiro | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Migrations | Version: 4.1
Severity: Normal | Resolution: wontfix
Keywords: migrations, | Triage Stage:
unique_constraint, | Unreviewed
UniqeConstraint |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Joel Shapiro):

Replying to [comment:2 Mariusz Felisiak]:


> Thanks for this ticket, however, I'm against this change. First of all
it is backward incompatible. Constraints have been introduced in Django
2.2 and constraints with a name of length greater than 63 characters are
valid on other databases (64 on MySQL, 128 on MSSQL, etc.). I agree that
it is a inconsistency between constraints and indexes policy but still we
need to be careful with introducing incompatibilities. See also a related
ticket, #30614.
>
> Please first start a discussion on the DevelopersMailingList, where
you'll reach a wider audience and see what other think, and
[https://docs.djangoproject.com/en/stable/internals/contributing/triaging-
tickets/#closing-tickets follow the triaging guidelines with regards to
wontfix tickets].


Thanks for the fast response!

Yes, I agree. Not great to break compatibility.

--
Ticket URL: <https://code.djangoproject.com/ticket/34423#comment:3>

Reply all
Reply to author
Forward
0 new messages