Code

Opened 6 years ago

Closed 2 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)

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.

Attachments (0)

Change History (7)

comment:1 Changed 6 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design 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 Changed 5 years ago by ramiro

  • Description modified (diff)

(reformatted description)

comment:3 in reply to: ↑ description ; follow-up: Changed 5 years ago by aatif

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

comment:4 in reply to: ↑ 3 Changed 5 years ago by syabro

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 Changed 3 years ago by lukeplant

  • Severity set to Normal
  • Type set to Bug

comment:6 Changed 3 years ago by ramiro

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

comment:7 Changed 2 years ago by aaugustin

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

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.