diff options
| author | Jacek Bzdak <jbzdak@gmail.com> | 2015-11-06 17:29:23 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-11-25 13:15:35 -0500 |
| commit | 023bf66bff8aa09e67c7d397707d46d67ecc2c55 (patch) | |
| tree | c2ae07c78d990dfc10f3981060aa6c3198c17828 /django | |
| parent | e2231075ebeb04b529b9dd5136b6f70eaaf89cfa (diff) | |
[1.9.x] Fixed #25274 --- Made inspectdb handle renamed fields in unique_together.
Backport of 2cb50f935aa70e91dd6c2f253becd636a2eb6fb7 from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/commands/inspectdb.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py index 9b9e350f4b..7f55f5d022 100644 --- a/django/core/management/commands/inspectdb.py +++ b/django/core/management/commands/inspectdb.py @@ -71,6 +71,7 @@ class Command(BaseCommand): except NotImplementedError: constraints = {} used_column_names = [] # Holds column names used in the table so far + column_to_field_name = {} # Maps column names to names of model fields for row in connection.introspection.get_table_description(cursor, table_name): comment_notes = [] # Holds Field notes, to be displayed in a Python comment. extra_params = OrderedDict() # Holds Field parameters such as 'db_column'. @@ -83,6 +84,7 @@ class Command(BaseCommand): comment_notes.extend(notes) used_column_names.append(att_name) + column_to_field_name[column_name] = att_name # Add primary_key and unique, if necessary. if column_name in indexes: @@ -145,7 +147,7 @@ class Command(BaseCommand): if comment_notes: field_desc += ' # ' + ' '.join(comment_notes) yield ' %s' % field_desc - for meta_line in self.get_meta(table_name, constraints): + for meta_line in self.get_meta(table_name, constraints, column_to_field_name): yield meta_line def normalize_col_name(self, col_name, used_column_names, is_relation): @@ -242,7 +244,7 @@ class Command(BaseCommand): return field_type, field_params, field_notes - def get_meta(self, table_name, constraints): + def get_meta(self, table_name, constraints, column_to_field_name): """ Return a sequence comprising the lines of code necessary to construct the inner Meta class for the model corresponding @@ -255,7 +257,7 @@ class Command(BaseCommand): if len(columns) > 1: # we do not want to include the u"" or u'' prefix # so we build the string rather than interpolate the tuple - tup = '(' + ', '.join("'%s'" % c for c in columns) + ')' + tup = '(' + ', '.join("'%s'" % column_to_field_name[c] for c in columns) + ')' unique_together.append(tup) meta = ["", " class Meta:", |
