mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #8317 -- Corrected the inspectdb management command to properly set primary_key=True and unique=True on foreign keys. Thanks to bthomas for the report and patch, and to David Gouldin for the tests.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17451 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -62,15 +62,22 @@ class Command(NoArgsCommand):
|
||||
if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name) or column_name != att_name:
|
||||
extra_params['db_column'] = column_name
|
||||
|
||||
# Add primary_key and unique, if necessary.
|
||||
if column_name in indexes:
|
||||
if indexes[column_name]['primary_key']:
|
||||
extra_params['primary_key'] = True
|
||||
elif indexes[column_name]['unique']:
|
||||
extra_params['unique'] = True
|
||||
|
||||
# Modify the field name to make it Python-compatible.
|
||||
if ' ' in att_name:
|
||||
att_name = att_name.replace(' ', '_')
|
||||
comment_notes.append('Field renamed to remove spaces.')
|
||||
|
||||
|
||||
if '-' in att_name:
|
||||
att_name = att_name.replace('-', '_')
|
||||
comment_notes.append('Field renamed to remove dashes.')
|
||||
|
||||
|
||||
if column_name != att_name:
|
||||
comment_notes.append('Field name made lowercase.')
|
||||
|
||||
@@ -88,15 +95,8 @@ class Command(NoArgsCommand):
|
||||
extra_params.update(field_params)
|
||||
comment_notes.extend(field_notes)
|
||||
|
||||
# Add primary_key and unique, if necessary.
|
||||
if column_name in indexes:
|
||||
if indexes[column_name]['primary_key']:
|
||||
extra_params['primary_key'] = True
|
||||
elif indexes[column_name]['unique']:
|
||||
extra_params['unique'] = True
|
||||
|
||||
field_type += '('
|
||||
|
||||
|
||||
if keyword.iskeyword(att_name):
|
||||
att_name += '_field'
|
||||
comment_notes.append('Field renamed because it was a Python reserved word.')
|
||||
|
||||
Reference in New Issue
Block a user