But on this example, when the constraint fails, an integrity Error occur
and no update is in place
{{{
class Test(models.Model):
field1 = models.IntegerField(null=True, blank=True)
field2 = models.IntegerField(null=True, blank=True)
count = models.IntegerField(null=True, blank=True)
class Meta:
db_table = "test"
constraints = [
models.UniqueConstraint(
models.functions.Coalesce("field1", 0),
models.functions.Coalesce("field2", 0),
name="test_coal_unique",
),
models.UniqueConstraint(
"field1",
"field2",
name="test_unique",
),
]
t1 = Test(field1=1,field2=None,count=1)
t2 = Test(field1=1,field2=None,count=2)
Test.objects.bulk_create([t1, t2], ignore_conflicts=False,
update_conflicts=True, unique_fields=['field1','field2'], update_fields =
['count'])
}}}
{{{
django.db.utils.IntegrityError: duplicate key value violates unique
constraint "test_coal_unique"
DETAIL: Key (COALESCE(field1, 0), COALESCE(field2, 0))=(1, 0) already
exists.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34225>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.