From fed7f992ac8b2ccb5164761a609277513f10d963 Mon Sep 17 00:00:00 2001 From: Hannes Ljungberg Date: Sat, 4 Dec 2021 21:03:38 +0100 Subject: [4.0.x] Fixed #33335 -- Made model validation ignore functional unique constraints. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Regression in 3aa545281e0c0f9fac93753e3769df9e0334dbaa. Thanks Hervé Le Roy for the report. Backport of 1eaf38fa87384fe26d1abf6e389d6df1600d4d8c from main --- tests/validation/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/validation/models.py') diff --git a/tests/validation/models.py b/tests/validation/models.py index 3a5a9cd354..b2d705aed2 100644 --- a/tests/validation/models.py +++ b/tests/validation/models.py @@ -2,6 +2,7 @@ from datetime import datetime from django.core.exceptions import ValidationError from django.db import models +from django.db.models.functions import Lower def validate_answer_to_universe(value): @@ -125,3 +126,13 @@ class GenericIPAddressTestModel(models.Model): class GenericIPAddrUnpackUniqueTest(models.Model): generic_v4unpack_ip = models.GenericIPAddressField(null=True, blank=True, unique=True, unpack_ipv4=True) + + +class UniqueFuncConstraintModel(models.Model): + field = models.CharField(max_length=255) + + class Meta: + required_db_features = {'supports_expression_indexes'} + constraints = [ + models.UniqueConstraint(Lower('field'), name='func_lower_field_uq'), + ] -- cgit v1.3