Fixed #31745 -- Added error messages when using UniqueConstraint.include/opclasses with deferrable.
This commit is contained in:
parent
62d85a2835
commit
30e3d2d78d
|
@ -95,6 +95,14 @@ class UniqueConstraint(BaseConstraint):
|
|||
raise ValueError(
|
||||
'UniqueConstraint with conditions cannot be deferred.'
|
||||
)
|
||||
if include and deferrable:
|
||||
raise ValueError(
|
||||
'UniqueConstraint with include fields cannot be deferred.'
|
||||
)
|
||||
if opclasses and deferrable:
|
||||
raise ValueError(
|
||||
'UniqueConstraint with opclasses cannot be deferred.'
|
||||
)
|
||||
if not isinstance(deferrable, (type(None), Deferrable)):
|
||||
raise ValueError(
|
||||
'UniqueConstraint.deferrable must be a Deferrable instance.'
|
||||
|
|
|
@ -406,6 +406,26 @@ class UniqueConstraintTests(TestCase):
|
|||
deferrable=models.Deferrable.DEFERRED,
|
||||
)
|
||||
|
||||
def test_deferrable_with_include(self):
|
||||
message = 'UniqueConstraint with include fields cannot be deferred.'
|
||||
with self.assertRaisesMessage(ValueError, message):
|
||||
models.UniqueConstraint(
|
||||
fields=['name'],
|
||||
name='name_inc_color_color_unique',
|
||||
include=['color'],
|
||||
deferrable=models.Deferrable.DEFERRED,
|
||||
)
|
||||
|
||||
def test_deferrable_with_opclasses(self):
|
||||
message = 'UniqueConstraint with opclasses cannot be deferred.'
|
||||
with self.assertRaisesMessage(ValueError, message):
|
||||
models.UniqueConstraint(
|
||||
fields=['name'],
|
||||
name='name_text_pattern_ops_unique',
|
||||
opclasses=['text_pattern_ops'],
|
||||
deferrable=models.Deferrable.DEFERRED,
|
||||
)
|
||||
|
||||
def test_invalid_defer_argument(self):
|
||||
message = 'UniqueConstraint.deferrable must be a Deferrable instance.'
|
||||
with self.assertRaisesMessage(ValueError, message):
|
||||
|
|
Loading…
Reference in New Issue