﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30484	Add conditional expression support to CheckConstraint.	David Sanders	Simon Charette	"I'm wondering about the possibility of updating CheckConstraint to handle RawSQL expressions, in a similar way to annotate().

To illustrate the limitations of using Q objects and usefulness of RawSQL expressions consider the following example:

{{{
class Foo(models.Model):
    …
    total = models.IntegerField(blank=True, null=True)  # a calculated field
    total_last_updated = models.DateTimeField(blank=True, null=True)  # set when total is calculated
}}}

A check constraint would be useful here to enforce that `total_last_updated` is populated/cleared when total is populated/cleared and would be something like an XOR check with the following SQL expression: `(total IS NULL) = (total_last_updated IS NULL)`.  This doesn't appear to be possible with Q objects.

The workaround in this case is to create the check constraint manually with a RunSQL migration."	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	1	0	0	0	0	0
