|
9 | 9 | from functools import reduce
|
10 | 10 | from operator import or_
|
11 | 11 | from typing import Any, Generic, List, Optional, Tuple, Type, TypeVar, Union
|
12 |
| - |
| 12 | +from django import VERSION as django_version |
13 | 13 | from django.core.exceptions import ValidationError
|
14 | 14 | from django.core.validators import DecimalValidator
|
15 | 15 | from django.db.models import (
|
@@ -84,6 +84,9 @@ class _DatabaseDefault:
|
84 | 84 | PrimitiveT = TypeVar("PrimitiveT", bound=Type[SupportedPrimitive])
|
85 | 85 |
|
86 | 86 |
|
| 87 | +condition = "check" if django_version[0:2] < (5, 1) else "condition" |
| 88 | + |
| 89 | + |
87 | 90 | @deconstructible
|
88 | 91 | class EnumValidatorAdapter:
|
89 | 92 | """
|
@@ -749,9 +752,10 @@ def contribute_to_class(
|
749 | 752 | constraint |= Q(**{f"{name}__isnull": True})
|
750 | 753 | cls._meta.constraints = [ # pylint: disable=W0212
|
751 | 754 | *cls._meta.constraints, # pylint: disable=W0212
|
752 |
| - CheckConstraint( |
753 |
| - check=constraint, name=self.constraint_name(cls, name, self.enum) |
754 |
| - ), |
| 755 | + CheckConstraint(**{ |
| 756 | + condition: constraint, |
| 757 | + "name": self.constraint_name(cls, name, self.enum) |
| 758 | + }), |
755 | 759 | ] # pylint: disable=protected-access
|
756 | 760 | # this dictionary is used to serialize the model, so if constraints
|
757 | 761 | # is not present - they will not be added to migrations
|
@@ -1176,10 +1180,10 @@ def contribute_to_class(
|
1176 | 1180 |
|
1177 | 1181 | cls._meta.constraints = [ # pylint: disable=W0212
|
1178 | 1182 | *cls._meta.constraints, # pylint: disable=W0212
|
1179 |
| - CheckConstraint( |
1180 |
| - check=constraint, |
1181 |
| - name=self.constraint_name(cls, name, self.enum), |
1182 |
| - ), |
| 1183 | + CheckConstraint(**{ |
| 1184 | + condition: constraint, |
| 1185 | + "name": self.constraint_name(cls, name, self.enum), |
| 1186 | + }), |
1183 | 1187 | ]
|
1184 | 1188 | # this dictionary is used to serialize the model, so if
|
1185 | 1189 | # constraints is not present - they will not be added to
|
|
0 commit comments