diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index bc32ead930..e30deee29b 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1455,7 +1455,10 @@ class BaseQuery(object): self.update_dupe_avoidance(dupe_opts, dupe_col, alias) if pos != len(names) - 1: - raise FieldError("Join on field %r not permitted." % name) + if pos == len(names) - 2: + raise FieldError("Join on field %r not permitted. Did you misspell %r for the lookup type?" % (name, names[pos + 1])) + else: + raise FieldError("Join on field %r not permitted." % name) return field, target, opts, joins, last, extra_filters diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py index 1d39e0e22b..bc291963e4 100644 --- a/tests/modeltests/lookup/models.py +++ b/tests/modeltests/lookup/models.py @@ -293,7 +293,7 @@ FieldError: Cannot resolve keyword 'pub_date_year' into field. Choices are: head >>> Article.objects.filter(headline__starts='Article') Traceback (most recent call last): ... -FieldError: Join on field 'headline' not permitted. +FieldError: Join on field 'headline' not permitted. Did you misspell 'starts' for the lookup type? # Create some articles with a bit more interesting headlines for testing field lookups: >>> now = datetime.now()