diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index e9903a73b6..ea31096374 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -966,7 +966,7 @@ class AutoField(Field): return int(value) def contribute_to_class(self, cls, name, **kwargs): - assert not cls._meta.auto_field, "A model can't have more than one AutoField." + assert not cls._meta.auto_field, "Model %s can't have more than one AutoField." % cls._meta.label super().contribute_to_class(cls, name, **kwargs) cls._meta.auto_field = self diff --git a/tests/validation/models.py b/tests/validation/models.py index f954cc3a4f..953370bc37 100644 --- a/tests/validation/models.py +++ b/tests/validation/models.py @@ -130,4 +130,4 @@ try: auto2 = models.AutoField(primary_key=True) except AssertionError as exc: assertion_error = exc -assert str(assertion_error) == "A model can't have more than one AutoField." +assert str(assertion_error) == "Model validation.MultipleAutoFields can't have more than one AutoField."