Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Adrian Holovaty authored September 17, 2008
20  django/core/management/commands/inspectdb.py
@@ -41,16 +41,17 @@ def handle_inspection(self):
41 41
             except NotImplementedError:
42 42
                 indexes = {}
43 43
             for i, row in enumerate(connection.introspection.get_table_description(cursor, table_name)):
44  
-                att_name = row[0].lower()
  44
+                column_name = row[0]
  45
+                att_name = column_name.lower()
45 46
                 comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
46 47
                 extra_params = {}  # Holds Field parameters such as 'db_column'.
47 48
 
48  
-                # If we need to do field name modifiations, 
49  
-                # remember the original field name
50  
-                if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name):
51  
-                    extra_params['db_column'] = att_name
52  
-                  
53  
-                # Now modify the field name to make it python compatible.  
  49
+                # If the column name can't be used verbatim as a Python
  50
+                # attribute, set the "db_column" for this Field.
  51
+                if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name) or column_name != att_name:
  52
+                    extra_params['db_column'] = column_name
  53
+
  54
+                # Modify the field name to make it Python-compatible.
54 55
                 if ' ' in att_name:
55 56
                     att_name = att_name.replace(' ', '_')
56 57
                     comment_notes.append('Field renamed to remove spaces.')
@@ -60,6 +61,8 @@ def handle_inspection(self):
60 61
                 if keyword.iskeyword(att_name):
61 62
                     att_name += '_field'
62 63
                     comment_notes.append('Field renamed because it was a Python reserved word.')
  64
+                if column_name != att_name:
  65
+                    comment_notes.append('Field name made lowercase.')
63 66
 
64 67
                 if i in relations:
65 68
                     rel_to = relations[i][1] == table_name and "'self'" or table2model(relations[i][1])
@@ -67,7 +70,7 @@ def handle_inspection(self):
67 70
                     if att_name.endswith('_id'):
68 71
                         att_name = att_name[:-3]
69 72
                     else:
70  
-                        extra_params['db_column'] = att_name
  73
+                        extra_params['db_column'] = column_name
71 74
                 else:
72 75
                     try:
73 76
                         field_type = connection.introspection.data_types_reverse[row[1]]
@@ -90,7 +93,6 @@ def handle_inspection(self):
90 93
                         extra_params['decimal_places'] = row[5]
91 94
 
92 95
                     # Add primary_key and unique, if necessary.
93  
-                    column_name = extra_params.get('db_column', att_name)
94 96
                     if column_name in indexes:
95 97
                         if indexes[column_name]['primary_key']:
96 98
                             extra_params['primary_key'] = True

0 notes on commit 26a9ac4

Please sign in to comment.
Something went wrong with that request. Please try again.