| 210 | return schema_editor._delete_check_sql(model, self.name) |
| 211 | |
| 212 | def validate(self, model, instance, exclude=None, using=DEFAULT_DB_ALIAS): |
| 213 | against = instance._get_field_expression_map(meta=model._meta, exclude=exclude) |
| 214 | # Ignore constraints with excluded fields in condition. |
| 215 | if exclude and self._expression_refs_exclude(model, self.condition, exclude): |
| 216 | return |
| 217 | condition = self.condition |
| 218 | if connections[using].features.supports_comparing_boolean_expr: |
| 219 | # Checks constraints do not fail when they evaluate to UNKNOWN. |
| 220 | condition = Coalesce(condition, True, output_field=BooleanField()) |
| 221 | if not Q(condition).check(against, using=using): |
| 222 | raise ValidationError( |
| 223 | self.get_violation_error_message(), code=self.violation_error_code |
| 224 | ) |
| 225 | |
| 226 | def __repr__(self): |
| 227 | return "<%s: condition=%s name=%s%s%s>" % ( |