Django

Code

Changeset 9053

Show
Ignore:
Timestamp:
09/17/08 00:12:53 (4 months ago)
Author:
adrian
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management/commands/inspectdb.py

    r8404 r9053  
    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 
    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. 
    5455                if ' ' in att_name: 
    5556                    att_name = att_name.replace(' ', '_') 
     
    6162                    att_name += '_field' 
    6263                    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.') 
    6366 
    6467                if i in relations: 
     
    6871                        att_name = att_name[:-3] 
    6972                    else: 
    70                         extra_params['db_column'] = att_name 
     73                        extra_params['db_column'] = column_name 
    7174                else: 
    7275                    try: 
     
    9194 
    9295                    # Add primary_key and unique, if necessary. 
    93                     column_name = extra_params.get('db_column', att_name) 
    9496                    if column_name in indexes: 
    9597                        if indexes[column_name]['primary_key']: