diff options
| author | Michael Sinov <sihaelov@gmail.com> | 2016-12-13 21:38:09 +1000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-03-21 12:28:16 -0400 |
| commit | 9aca67bea8d42e6c1889f16e5ce297cfc23b91a2 (patch) | |
| tree | 19b7ebd6b5a324a5be2a3a5da66d8b208635225b /django | |
| parent | a170dac887ba17afb0adb7a837410dd26471f097 (diff) | |
Fixed #27533 -- Fixed inspectdb crash if a unique constraint uses an unsupported type.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/commands/inspectdb.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py index 31c4ae062b..c84ce14739 100644 --- a/django/core/management/commands/inspectdb.py +++ b/django/core/management/commands/inspectdb.py @@ -269,16 +269,24 @@ class Command(BaseCommand): to the given database table name. """ unique_together = [] + has_unsupported_constraint = False for params in constraints.values(): if params['unique']: columns = params['columns'] + if None in columns: + has_unsupported_constraint = True + columns = [x for x in columns if x is not None] if len(columns) > 1: unique_together.append(str(tuple(column_to_field_name[c] for c in columns))) managed_comment = " # Created from a view. Don't remove." if is_view else "" - meta = ["", - " class Meta:", - " managed = False%s" % managed_comment, - " db_table = '%s'" % table_name] + meta = [''] + if has_unsupported_constraint: + meta.append(' # A unique constraint could not be introspected.') + meta += [ + ' class Meta:', + ' managed = False%s' % managed_comment, + ' db_table = %r' % table_name + ] if unique_together: tup = '(' + ', '.join(unique_together) + ',)' meta += [" unique_together = %s" % tup] |
