diff --git a/django/db/models/query.py b/django/db/models/query.py index a5b0f464a9b..5ac2407ea36 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1135,8 +1135,8 @@ class QuerySet(AltersData): self._not_support_combined_queries("delete") if self.query.is_sliced: raise TypeError("Cannot use 'limit' or 'offset' with delete().") - if self.query.distinct or self.query.distinct_fields: - raise TypeError("Cannot call delete() after .distinct().") + if self.query.distinct_fields: + raise TypeError("Cannot call delete() after .distinct(*fields).") if self._fields is not None: raise TypeError("Cannot call delete() after .values() or .values_list()") diff --git a/tests/delete_regress/tests.py b/tests/delete_regress/tests.py index 2540fd2802e..71e3bcb405f 100644 --- a/tests/delete_regress/tests.py +++ b/tests/delete_regress/tests.py @@ -396,10 +396,8 @@ class DeleteTests(TestCase): class DeleteDistinct(SimpleTestCase): - def test_disallowed_delete_distinct(self): - msg = "Cannot call delete() after .distinct()." - with self.assertRaisesMessage(TypeError, msg): - Book.objects.distinct().delete() + def test_disallowed_delete_distinct_on(self): + msg = "Cannot call delete() after .distinct(*fields)." with self.assertRaisesMessage(TypeError, msg): Book.objects.distinct("id").delete()