summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJean-Louis Fuchs <ganwell@fangorn.ch>2015-03-05 13:41:15 +0100
committerMarkus Holtermann <info@markusholtermann.eu>2015-03-07 14:09:56 +0100
commitf4f0060feaee6bbd76a0d575487682bc541111e4 (patch)
tree2ea7605a79863e91bbdf9cb864feb0ad87f2fc0d /django
parentc36b60836be9e78ab877566cc43dc03960ce944d (diff)
Fixed #24447 -- Made migrations add FK constraints for existing columns
When altering from e.g. an IntegerField to a ForeignKey, Django didn't add a constraint.
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/base/schema.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py
index 239af12446..8d019a7983 100644
--- a/django/db/backends/base/schema.py
+++ b/django/db/backends/base/schema.py
@@ -709,9 +709,9 @@ class BaseDatabaseSchemaEditor(object):
}
)
# Does it have a foreign key?
- if new_field.rel and \
- (fks_dropped or (old_field.rel and not old_field.db_constraint)) and \
- new_field.db_constraint:
+ if (new_field.rel and
+ (fks_dropped or not old_field.rel or not old_field.db_constraint) and
+ new_field.db_constraint):
self.execute(self._create_fk_sql(model, new_field, "_fk_%(to_table)s_%(to_column)s"))
# Rebuild FKs that pointed to us if we previously had to drop them
if old_field.primary_key and new_field.primary_key and old_type != new_type: