Opened 16 years ago
Last modified 13 years ago
#9116 closed
different caps in application name producing error — at Version 2
Reported by: | 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 )
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:
- Generate SQL
'CREATE TABLE `tablename` IF NOT EXIST'
- Check MySQL's
lower_case_table_names
variable and change condition on line 67.
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.