Author: adrian
Date: 2008-09-17 00:12:53 -0500 (Wed, 17 Sep 2008)
New Revision: 9053
Modified:
django/trunk/django/core/management/commands/inspectdb.py
Log:
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
Modified: django/trunk/django/core/management/commands/inspectdb.py
===================================================================
--- django/trunk/django/core/management/commands/inspectdb.py 2008-09-17
04:56:04 UTC (rev 9052)
+++ django/trunk/django/core/management/commands/inspectdb.py 2008-09-17
05:12:53 UTC (rev 9053)
@@ -41,16 +41,17 @@
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 @@
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 @@
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 @@
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---