Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #8573 -- Fixed bug in 'inspectdb' regarding case-sensitivity of…

… field names. It was automatically lowercasing the column name to create the Field name, which was inaccurate in the case of column names that contained a capital letter. Thanks for reporting and detective work, ramiro

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9053 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 26a9ac491cb77642d31cc7e7ab7418593b1979e7 1 parent 660180d
@adrianholovaty adrianholovaty authored
Showing with 11 additions and 9 deletions.
  1. +11 −9 django/core/management/commands/inspectdb.py
View
20 django/core/management/commands/inspectdb.py
@@ -41,16 +41,17 @@ def handle_inspection(self):
except NotImplementedError:
indexes = {}
for i, row in enumerate(connection.introspection.get_table_description(cursor, table_name)):
- att_name = row[0].lower()
+ column_name = row[0]
+ att_name = column_name.lower()
comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
extra_params = {} # Holds Field parameters such as 'db_column'.
- # If we need to do field name modifiations,
- # remember the original field name
- if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name):
- extra_params['db_column'] = att_name
-
- # Now modify the field name to make it python compatible.
+ # If the column name can't be used verbatim as a Python
+ # attribute, set the "db_column" for this Field.
+ if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name) or column_name != att_name:
+ extra_params['db_column'] = column_name
+
+ # Modify the field name to make it Python-compatible.
if ' ' in att_name:
att_name = att_name.replace(' ', '_')
comment_notes.append('Field renamed to remove spaces.')
@@ -60,6 +61,8 @@ def handle_inspection(self):
if keyword.iskeyword(att_name):
att_name += '_field'
comment_notes.append('Field renamed because it was a Python reserved word.')
+ if column_name != att_name:
+ comment_notes.append('Field name made lowercase.')
if i in relations:
rel_to = relations[i][1] == table_name and "'self'" or table2model(relations[i][1])
@@ -67,7 +70,7 @@ def handle_inspection(self):
if att_name.endswith('_id'):
att_name = att_name[:-3]
else:
- extra_params['db_column'] = att_name
+ extra_params['db_column'] = column_name
else:
try:
field_type = connection.introspection.data_types_reverse[row[1]]
@@ -90,7 +93,6 @@ def handle_inspection(self):
extra_params['decimal_places'] = row[5]
# Add primary_key and unique, if necessary.
- column_name = extra_params.get('db_column', att_name)
if column_name in indexes:
if indexes[column_name]['primary_key']:
extra_params['primary_key'] = True
Please sign in to comment.
Something went wrong with that request. Please try again.