Opened 5 years ago
Last modified 4 years ago
#31530 closed Cleanup/optimization
Check that CheckConstraint.check and UniqueConstraint.condition don't span joins. — at Initial Version
Reported by: | Simon Charette | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Similar to #31410 but for check
and condition
.
---
Not everyone is familiar with the fact database level constraint cannot span across tables and might be tempted to do
class Person(models.Model): age = models.PositiveSmallIntegerField() parent = models.ForeignKey(self) class Meta: constraints = { CheckConstraint( name='age_lt_parent', check=Q(age__lt=parent__age) ), }
Which we'll happily create migrations for but we'll then crash because we prevent JOINs when resolving check
.
Note:
See TracTickets
for help on using tickets.