diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py index 191e72c53a..1e1376a4e2 100644 --- a/django/db/backends/schema.py +++ b/django/db/backends/schema.py @@ -437,7 +437,7 @@ class BaseDatabaseSchemaEditor(object): } ) # Drop any FK constraints, we'll remake them later - if getattr(old_field, "rel"): + if old_field.rel: fk_names = self._constraint_names(model, [old_field.column], foreign_key=True) if strict and len(fk_names) != 1: raise ValueError("Found wrong number (%s) of foreign key constraints for %s.%s" % ( @@ -584,7 +584,7 @@ class BaseDatabaseSchemaEditor(object): } ) # Does it have a foreign key? - if getattr(new_field, "rel"): + if new_field.rel: self.execute( self.sql_create_fk % { "table": self.quote_name(model._meta.db_table), diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index ff5957fe7e..2771bcbc68 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -46,8 +46,8 @@ class MigrationAutodetector(object): # Are there any relationships out from this model? if so, punt it to the next phase. related_fields = [] for field in new_app_cache.get_model(app_label, model_name)._meta.fields: - if hasattr(field, "rel"): - if hasattr(field.rel, "to"): + if field.rel: + if field.rel.to: related_fields.append((field.name, field.rel.to._meta.app_label.lower(), field.rel.to._meta.object_name.lower())) if hasattr(field.rel, "through") and not field.rel.though._meta.auto_created: related_fields.append((field.name, field.rel.through._meta.app_label.lower(), field.rel.through._meta.object_name.lower()))