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
This commit is contained in:
Adrian Holovaty 2008-09-17 05:12:53 +00:00
parent 660180df30
commit 26a9ac491c
1 changed files with 11 additions and 9 deletions

View File

@ -41,16 +41,17 @@ class Command(NoArgsCommand):
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 @@ class Command(NoArgsCommand):
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 @@ class Command(NoArgsCommand):
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 @@ class Command(NoArgsCommand):
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