Ticket #8573: inspectdb_fk_uppercase_fields.diff

File inspectdb_fk_uppercase_fields.diff, 2.0 KB (added by ramiro, 7 years ago)
  • django/core/management/commands/inspectdb.py

    diff -r f561ce6b959a django/core/management/commands/inspectdb.py
    a b class Command(NoArgsCommand): 
    4141            except NotImplementedError:
    4242                indexes = {}
    4343            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()
    4546                comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
    4647                extra_params = {}  # Holds Field parameters such as 'db_column'.
    4748
    4849                # If we need to do field name modifiations,
    4950                # remember the original field name
    5051                if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name):
    51                     extra_params['db_column'] = att_name
     52                    extra_params['db_column'] = column_name
    5253                 
    5354                # Now modify the field name to make it python compatible. 
    5455                if ' ' in att_name:
    class Command(NoArgsCommand): 
    6768                    if att_name.endswith('_id'):
    6869                        att_name = att_name[:-3]
    6970                    else:
    70                         extra_params['db_column'] = att_name
     71                        extra_params['db_column'] = column_name
    7172                else:
    7273                    try:
    7374                        field_type = connection.introspection.data_types_reverse[row[1]]
    class Command(NoArgsCommand): 
    9091                        extra_params['decimal_places'] = row[5]
    9192
    9293                    # Add primary_key and unique, if necessary.
    93                     column_name = extra_params.get('db_column', att_name)
    9494                    if column_name in indexes:
    9595                        if indexes[column_name]['primary_key']:
    9696                            extra_params['primary_key'] = True
Back to Top