diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index f9b4bfb..73b34ac 100644
a
|
b
|
class Command(BaseCommand):
|
120 | 120 | rel_type = 'OneToOneField' |
121 | 121 | else: |
122 | 122 | rel_type = 'ForeignKey' |
| 123 | |
| 124 | |
| 125 | related_model = relations[column_name][1] |
| 126 | related_column = relations[column_name][0] |
| 127 | related_pk_col = connection.introspection.get_primary_key_column(cursor, related_model) |
| 128 | |
| 129 | if related_pk_col is not None and related_column != related_pk_col: |
| 130 | extra_params["to_field"] = related_column |
| 131 | |
123 | 132 | rel_to = ( |
124 | | "self" if relations[column_name][1] == table_name |
125 | | else table2model(relations[column_name][1]) |
| 133 | "self" if related_model == table_name |
| 134 | else table2model(related_model) |
126 | 135 | ) |
| 136 | |
127 | 137 | if rel_to in known_models: |
128 | 138 | field_type = '%s(%s' % (rel_type, rel_to) |
129 | 139 | else: |