diff options
| author | Jean-Louis Fuchs <ganwell@fangorn.ch> | 2015-03-05 13:41:15 +0100 |
|---|---|---|
| committer | Markus Holtermann <info@markusholtermann.eu> | 2015-03-07 14:30:28 +0100 |
| commit | 283b630d6324c936cbe42d8f0169f056b3ba59c6 (patch) | |
| tree | 05dd1670feafc1a34d1c3be3c44bd359b5e29279 /django | |
| parent | 7f2d60996ca26003d35bead426b10fd8dd908347 (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.
Backport of f4f0060feaee6bbd76a0d575487682bc541111e4 from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/schema.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py index 54e6e06c4f..4a5637c8da 100644 --- a/django/db/backends/schema.py +++ b/django/db/backends/schema.py @@ -675,9 +675,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: |
