Opened 10 years ago
Closed 8 years ago
#24442 closed Bug (fixed)
Index name truncation is odd
Reported by: | Shai Berger | Owned by: | Akshesh Doshi |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | oracle |
Cc: | Markus Holtermann | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The code that generates index names for migrations (https://github.com/django/django/blob/8ca35d7c6a639933927f45b439363a1614da56f1/django/db/backends/base/schema.py#L789) behaves in undesired ways when the name it has created turns out to be too long. It starts by cutting out parts of the table name (with no compensation hash), which could lead to name-uniqueness violations; and in case this wasn't enough, just gives up on meaningful naming and replaces the whole name with a digest.
We should do better. Here's one suggestion: divide the available name length into 3 equal parts -- one for the table name, one for the first column name, and one for the uniqueness-digest and suffix. Make each part fit its size by the normal truncation method, replacing its end with a 4-hexdigit hash if necessary.
I'm tempted to mark this a blocker -- so that we don't end up with incorrectly named indexes in the wild.
Change History (4)
comment:1 by , 10 years ago
Cc: | added |
---|
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
This is related to f37c11eea3cb860112a26f8a65d823842f65b96f and #24390.