Django doesn't group by if I omit order_by() clause

I was trying to find an answer for this question in documentation but I unfortunately did not succeed. In documentation it states that if I want to group my objects and Count them I should use the following:

MyObject.objects.values('field_to_group_by').annotate(Count('field_to_count'))

However it doesn't work. But when I add simple order_by it does:

MyObject.objects.values('field_to_group_by').annotate(Count('field_to_count')).order_by()

Any idea why is that? They didn't mention that in documentation.

Back to Top