Code

Ticket #8573: inspectdb_fk_uppercase_fields.diff

File inspectdb_fk_uppercase_fields.diff, 2.0 KB (added by ramiro, 6 years ago)
Line 
1diff -r f561ce6b959a django/core/management/commands/inspectdb.py
2--- a/django/core/management/commands/inspectdb.py      Tue Aug 26 05:58:07 2008 -0300
3+++ b/django/core/management/commands/inspectdb.py      Tue Aug 26 18:23:22 2008 -0300
4@@ -41,14 +41,15 @@ class Command(NoArgsCommand):
5             except NotImplementedError:
6                 indexes = {}
7             for i, row in enumerate(connection.introspection.get_table_description(cursor, table_name)):
8-                att_name = row[0].lower()
9+                column_name = row[0]
10+                att_name = column_name.lower()
11                 comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
12                 extra_params = {}  # Holds Field parameters such as 'db_column'.
13 
14                 # If we need to do field name modifiations,
15                 # remember the original field name
16                 if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name):
17-                    extra_params['db_column'] = att_name
18+                    extra_params['db_column'] = column_name
19                   
20                 # Now modify the field name to make it python compatible. 
21                 if ' ' in att_name:
22@@ -67,7 +68,7 @@ class Command(NoArgsCommand):
23                     if att_name.endswith('_id'):
24                         att_name = att_name[:-3]
25                     else:
26-                        extra_params['db_column'] = att_name
27+                        extra_params['db_column'] = column_name
28                 else:
29                     try:
30                         field_type = connection.introspection.data_types_reverse[row[1]]
31@@ -90,7 +91,6 @@ class Command(NoArgsCommand):
32                         extra_params['decimal_places'] = row[5]
33 
34                     # Add primary_key and unique, if necessary.
35-                    column_name = extra_params.get('db_column', att_name)
36                     if column_name in indexes:
37                         if indexes[column_name]['primary_key']:
38                             extra_params['primary_key'] = True