[Answer]-How to keep django from creating join on parent=None

1👍

The proper way to require in a Django filter that a nullable field be null is to use an __isnull argument, not equality:

a_qs = Album.objects.filter(parent__isnull=True)

But I see that you’ve tried that. It turns out that this is a known bug in Django, corrected in the current development version but not in 1.5 or sooner:

https://code.djangoproject.com/ticket/10790

You could work around the error in the query by using an extra clause:

a_qs = Album.objects.extra(where=["parent_id is null"])

Leave a comment