diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 4a12d74452..d0e791ba20 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -317,7 +317,7 @@ class SQLCompiler(object): for name in self.query.distinct_fields: parts = name.split(LOOKUP_SEP) - field, col, alias, _, _ = self._setup_joins(parts, opts) + field, col, alias, _, _ = self._setup_joins(parts, opts, None) col, alias = self._final_join_removal(col, alias) result.append("%s.%s" % (qn(alias), qn2(col))) return result