Opened 16 years ago

Closed 12 years ago

#9116 closed Bug (wontfix)

different caps in application name producing error

Reported by: Maxim Syabro <syabro@…> Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Normal Keywords: inspectdb
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

I have an application with name localModels and lower_case_table_names mysql variable=1, which said to MySQL automatically convert table name to lowercase.
Let's look in djnago.core.management.commnads.syncdb.py, line 67:

if connection.introspection.table_name_converter(model._meta.db_table) in tables:
    continue

connection.introspection.table_name_converter(model._meta.db_table) = 'localModels_tablename'
in tables we have
(..., 'localmodels_tablename', ...)
so here your condition doesn't work, beacuse 'localModels_tablename'!='localmodels_tablename'.
And we have an exception in manage.py syncdb:

_mysql_exceptions.OperationalError: (1050, "Table 'localmodels_tablename' already exists")

So I see at least 2 ways:

  1. Generate SQL 'CREATE TABLE `tablename` IF NOT EXIST'
  2. Check MySQL's lower_case_table_names variable and change condition on line 67.

Change History (7)

comment:1 by Karen Tracey, 15 years ago

Triage Stage: UnreviewedDesign decision needed

This has come up on django-users as well: http://groups.google.com/group/django-users/browse_thread/thread/9b3830c369a97f1a/37d3389f481c9b7c?

I tend to think it's not necessary to put code in Django to deal with this. People running MySQL on Windows can configure it to preserve the case of the table names it is given, or specify the all-lowercase name MySQL will use in the model's Meta db_table parameter, or just avoid using mixed-case in the app name.

comment:2 by Ramiro Morales, 15 years ago

Description: modified (diff)

(reformatted description)

in reply to:  description ; comment:3 by aatif, 15 years ago

How can I check both of these? i-e lower_case_table_names and create ... if not exists.

in reply to:  3 comment:4 by Maxim Syabro, 15 years ago

Replying to aatif:

How can I check both of these? i-e lower_case_table_names and create ... if not exists.

By query "SHOW variables like 'lower_case_table_names'"

comment:5 by Luke Plant, 13 years ago

Severity: Normal
Type: Bug

comment:6 by Ramiro Morales, 13 years ago

Easy pickings: unset
Keywords: inspectdb added
UI/UX: unset

comment:7 by Aymeric Augustin, 12 years ago

Resolution: wontfix
Status: newclosed

MySQL's behavior with regard to case-sensitivity was discussed thoroughly in #16592, and one of the most knowledgeable contributors on MySQL support reached this conclusion:

I think the problematic behavior is due to the bugs and inconsistencies of MySQL. I don't think there is a straightforward solution to this that doesn't involve a lot of weird hacking around and exceptions.

Trying to fix things in Django would be very complicated and is likely to make things worse. I totally agree with Karen's conclusion in the first comment.

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