Opened 6 years ago

Closed 5 years ago

#11658 closed (fixed)

mysql backend doesn't define a max_name_length()

Reported by: abeld@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

MySql has a limit on the length of table, constaint, etc. names
(http://dev.mysql.com/doc/refman/4.1/en/identifiers.html), however, a
max_name_length() is not defined in django/db/backends/mysql/base.py

This means that long model names can trigger #1820 (In my case, a name
of a constraint was too long, ending up triggering this bug, even
though comment no. 6 on that ticket (http://code.djangoproject.com/ticket/1820#comment:6)
claims that is solved for constaints.)

Another comment might be comment no. 7 on #10358
(http://code.djangoproject.com/ticket/10358#comment:7) which mentions
a lack of max_name_length() but somehow doesn't consider this a
problem.

In my case, adding the following:

   def max_name_length(self):
       return 64

to DatabaseOperations in django/db/backends/mysql/base.py appears to
solve the

_mysql_exceptions.OperationalError: (1059, "Identifier name 'somelongmodelname_id_refs_question_ptr_id_8c9b12fefd7d140' is too long")

problem

Change History (2)

comment:1 Changed 6 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 1.0 to SVN

comment:2 Changed 5 years ago by ramiro

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in #13040.

Note: See TracTickets for help on using tickets.
Back to Top