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. 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/f89fa330-0c6b-43eb-ae86-7926b67669ab%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.