Fixed #35103 -- Used provided error code and message when fields is set without a condition on UniqueConstraint.

This commit is contained in:
gabn88 2024-01-11 17:43:52 +01:00 committed by Sarah Boyce
parent 1979b1403a
commit e970bb7ca7
5 changed files with 89 additions and 23 deletions

View file

@ -72,15 +72,13 @@ class GeneratedFieldVirtualProduct(models.Model):
class UniqueConstraintProduct(models.Model):
name = models.CharField(max_length=255)
color = models.CharField(max_length=32, null=True)
age = models.IntegerField(null=True)
class Meta:
constraints = [
models.UniqueConstraint(
fields=["name", "color"],
name="name_color_uniq",
# Custom message and error code are ignored.
violation_error_code="custom_code",
violation_error_message="Custom message",
)
]