mirror of
https://github.com/django/django.git
synced 2025-08-02 01:53:15 +00:00
Fixed #35638 -- Updated validate_constraints to consider db_default.
This commit is contained in:
parent
91a038754b
commit
509763c799
10 changed files with 130 additions and 13 deletions
|
@ -434,7 +434,7 @@ class Migration(migrations.Migration):
|
|||
primary_key=True,
|
||||
),
|
||||
),
|
||||
("ints", IntegerRangeField(null=True, blank=True)),
|
||||
("ints", IntegerRangeField(null=True, blank=True, db_default=(5, 10))),
|
||||
("bigints", BigIntegerRangeField(null=True, blank=True)),
|
||||
("decimals", DecimalRangeField(null=True, blank=True)),
|
||||
("timestamps", DateTimeRangeField(null=True, blank=True)),
|
||||
|
|
|
@ -130,7 +130,7 @@ class LineSavedSearch(PostgreSQLModel):
|
|||
|
||||
|
||||
class RangesModel(PostgreSQLModel):
|
||||
ints = IntegerRangeField(blank=True, null=True)
|
||||
ints = IntegerRangeField(blank=True, null=True, db_default=(5, 10))
|
||||
bigints = BigIntegerRangeField(blank=True, null=True)
|
||||
decimals = DecimalRangeField(blank=True, null=True)
|
||||
timestamps = DateTimeRangeField(blank=True, null=True)
|
||||
|
|
|
@ -1213,3 +1213,12 @@ class ExclusionConstraintTests(PostgreSQLTestCase):
|
|||
constraint_name,
|
||||
self.get_constraints(ModelWithExclusionConstraint._meta.db_table),
|
||||
)
|
||||
|
||||
def test_database_default(self):
|
||||
constraint = ExclusionConstraint(
|
||||
name="ints_equal", expressions=[("ints", RangeOperators.EQUAL)]
|
||||
)
|
||||
RangesModel.objects.create()
|
||||
msg = "Constraint “ints_equal” is violated."
|
||||
with self.assertRaisesMessage(ValidationError, msg):
|
||||
constraint.validate(RangesModel, RangesModel())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue