mirror of
https://github.com/django/django.git
synced 2024-12-25 10:35:48 +00:00
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:
parent
660180df30
commit
26a9ac491c
@ -41,16 +41,17 @@ class Command(NoArgsCommand):
|
|||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
indexes = {}
|
indexes = {}
|
||||||
for i, row in enumerate(connection.introspection.get_table_description(cursor, table_name)):
|
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.
|
comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
|
||||||
extra_params = {} # Holds Field parameters such as 'db_column'.
|
extra_params = {} # Holds Field parameters such as 'db_column'.
|
||||||
|
|
||||||
# If we need to do field name modifiations,
|
# If the column name can't be used verbatim as a Python
|
||||||
# remember the original field name
|
# attribute, set the "db_column" for this Field.
|
||||||
if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name):
|
if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name) or column_name != att_name:
|
||||||
extra_params['db_column'] = att_name
|
extra_params['db_column'] = column_name
|
||||||
|
|
||||||
# Now modify the field name to make it python compatible.
|
# Modify the field name to make it Python-compatible.
|
||||||
if ' ' in att_name:
|
if ' ' in att_name:
|
||||||
att_name = att_name.replace(' ', '_')
|
att_name = att_name.replace(' ', '_')
|
||||||
comment_notes.append('Field renamed to remove spaces.')
|
comment_notes.append('Field renamed to remove spaces.')
|
||||||
@ -60,6 +61,8 @@ class Command(NoArgsCommand):
|
|||||||
if keyword.iskeyword(att_name):
|
if keyword.iskeyword(att_name):
|
||||||
att_name += '_field'
|
att_name += '_field'
|
||||||
comment_notes.append('Field renamed because it was a Python reserved word.')
|
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:
|
if i in relations:
|
||||||
rel_to = relations[i][1] == table_name and "'self'" or table2model(relations[i][1])
|
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'):
|
if att_name.endswith('_id'):
|
||||||
att_name = att_name[:-3]
|
att_name = att_name[:-3]
|
||||||
else:
|
else:
|
||||||
extra_params['db_column'] = att_name
|
extra_params['db_column'] = column_name
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
field_type = connection.introspection.data_types_reverse[row[1]]
|
field_type = connection.introspection.data_types_reverse[row[1]]
|
||||||
@ -90,7 +93,6 @@ class Command(NoArgsCommand):
|
|||||||
extra_params['decimal_places'] = row[5]
|
extra_params['decimal_places'] = row[5]
|
||||||
|
|
||||||
# Add primary_key and unique, if necessary.
|
# Add primary_key and unique, if necessary.
|
||||||
column_name = extra_params.get('db_column', att_name)
|
|
||||||
if column_name in indexes:
|
if column_name in indexes:
|
||||||
if indexes[column_name]['primary_key']:
|
if indexes[column_name]['primary_key']:
|
||||||
extra_params['primary_key'] = True
|
extra_params['primary_key'] = True
|
||||||
|
Loading…
Reference in New Issue
Block a user