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.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Simon Charette
Sent: Monday, December 11, 2017 1:35 PM
To: Django users
Subject: Re: PRIMARY KEY in view PostgreSQL

Hello Matthew,

This should be fixed in Django 2.0 by 
daf2bd3efe53cbfc1c9fd00222b8315708023792[0].

I'd appreciate if you could chime in the related django-developer thread[1] to 
mention
you were using an unmanaged model to query views as there was no consensus
regarding whether or not the patch should be rolled back.

I think you're a great example of a user who hit this issue from starting to 
use Django
< 2.0 that is not taken into account by one of the user argument to favor 
rolling back
the patch[2].

The more I think of it the more I feel like we should just close the ticket 
until the
ORM gains enough introspection power to determine whether or not we should be
using the optimization on unmanaged model.

Here's the Trac ticket for reference[2].

Cheers,
Simon

[0] 
https://github.com/django/django/commit/daf2bd3efe53cbfc1c9fd00222b8315708023792
[1] https://groups.google.com/forum/#!topic/django-developers/lx3ZSq-W9X4
[2| https://groups.google.com/d/msg/django-developers/lx3ZSq-W9X4/yh4I2CsoBwAJ
[3] https://code.djangoproject.com/ticket/28107


Le lundi 11 décembre 2017 10:43:34 UTC-5, Matthew Pava a écrit :
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!
--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@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<https://groups.google.com/d/msgid/django-users/f89fa330-0c6b-43eb-ae86-7926b67669ab%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to django-users@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/ca01c5114c6e474e8f303bfb2be00c17%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

Reply via email to