mercredi 4 mai 2016

Django annotate/count filter only working with postgres not sqlite

Following model relations:

  • classA has a non-nullable FK-Field to classC.
  • classB has a nullable FK-Field to classC.

I need a list of classA-records that have zero classB-records connected to the common classC-record.

In postgres both queries give me what I want, while in sqlite they both give me a empty result:

ClassA.objects.annotate(num_classb=Count('classc__classbs')).filter(num_classb=0)

ClassA.objects.filter(classc__classbs__isnull=True)

Where do I go wrong? I did not find something about differences in the handling of such filters/annotations between postgres and sqlite

Aucun commentaire:

Enregistrer un commentaire