Added model name to AutoField error message.

This commit is contained in:
Almad 2018-03-03 19:22:00 +01:00 committed by Tim Graham
parent a20aae414e
commit 3d8fadad0f
2 changed files with 2 additions and 2 deletions

View File

@ -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

View File

@ -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."