Hello, I'm having issues getting multiple constraints to work (in postgres, if it matters). Here is the Meta:
class Meta: constraints = [ CheckConstraint( check=(Q(target_value__gt=0) & ~Q(target_metric=DEFAULT)) | (Q(enabled=False) | Q(status=IMPORTING) | Q(status=IMPORT_FAILURE)), name="positive_target_value", ) ] It would seem straightforward enough to me, but it ends up not working. Here is the generated SQL (pulled from the db itself): target_value > 0.0::double precision AND NOT target_metric::text = 'DEFAULT' ::text OR enabled = false OR status = 20 OR status = 30 And here is proof that it should actually work (pulled from a django console, where the conditions are copied from the migration file): Folder.objects.filter(models.Q(models.Q(('target_value__gt', 0), models.Q(_negated=True, target_metric='DEFAULT')), ('enabled', False), ('status', 20), ('status', 30), _connector='OR')) web_1 | Out[5]: <QuerySet [<Folder: aDifferentFolder>]> Folder.objects.filter(models.Q(models.Q(('target_value__gt', 0), models.Q(_negated=True, target_metric='**SOMETHING DIFFERENT**')), ('enabled', False), ('status', 20), ('status', 30), _connector='OR')) web_1 | Out[7]: <QuerySet [< Folder: Folder aDifferentFolder >, < Folder: Folder thisFolderShouldNotHaveBeenCreted>]> Anybody has any suggestion? Btw, I also tried switching the first condition with the second one, effectively putting the AND at the bottom of the query, but it didn't seem to have any effect. Thanks a lot. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dc746463-ef4c-4e17-9251-572ed374c0a4%40googlegroups.com.