Fellow users,
I have an unmanaged model that references a view in my PostgreSQL 9.5 backend. I am trying to apply an annotation through the ORM in that model’s manager. Unfortunately, I am getting an error that some fields “must appear in the GROUP BY clause or be used in an aggregate function.”
Upon further investigation, it appears that I need a PRIMARY KEY in the backend to avoid having to include columns in a GROUP BY clause, but PostgreSQL does not allow for such constraints to be added to a VIEW. The “id” column is just a row_number().
I was wondering how anyone else handled this issue.
Thanks!
Thank you so much, Simon, for that response! I do wish I could use Django 2.0, but some of my third-party apps haven’t been updated yet. I’m using Django 1.11.
With the clues provided, I was able to test my query by adding all of the columns into the GROUP BY clause in my PostgreSQL SQL editor. In the process, I learned that my query takes way too long to run (about 5 minutes).
As you requested, I added a message to the django-developers mailing list on that particular thread.
--
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...@googlegroups.com.
To post to this group, send email to
django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/f89fa330-0c6b-43eb-ae86-7926b67669ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.