Ticket #8317: primary_fk.diff

File primary_fk.diff, 1.6 KB (added by Bob Thomas, 16 years ago)

Move the code that sets primary_key=True above the check for foreign keys

  • django/core/management/commands/inspectdb.py

     
    4545                comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
    4646                extra_params = {}  # Holds Field parameters such as 'db_column'.
    4747
     48                # Add primary_key and unique, if necessary.
     49                if att_name in indexes:
     50                    if indexes[att_name]['primary_key']:
     51                        extra_params['primary_key'] = True
     52                    elif indexes[att_name]['unique']:
     53                        extra_params['unique'] = True
     54
    4855                if ' ' in att_name:
    4956                    extra_params['db_column'] = att_name
    5057                    att_name = att_name.replace(' ', '')
     
    8289                        extra_params['max_digits'] = row[4]
    8390                        extra_params['decimal_places'] = row[5]
    8491
    85                     # Add primary_key and unique, if necessary.
    86                     column_name = extra_params.get('db_column', att_name)
    87                     if column_name in indexes:
    88                         if indexes[column_name]['primary_key']:
    89                             extra_params['primary_key'] = True
    90                         elif indexes[column_name]['unique']:
    91                             extra_params['unique'] = True
    92 
    9392                    field_type += '('
    9493
    9594                # Don't output 'id = meta.AutoField(primary_key=True)', because
Back to Top