From 3d8fadad0f7a3a32f28db034650182117ae071f7 Mon Sep 17 00:00:00 2001 From: Almad Date: Sat, 3 Mar 2018 19:22:00 +0100 Subject: [PATCH] Added model name to AutoField error message. --- django/db/models/fields/__init__.py | 2 +- tests/validation/models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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."