﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27241	Annotate doesn't work with PostgreSQL views anymore	Jaap Roes		"Using annotate on (unmanaged) models backed by views has stopped working and now throws a:

`psycopg2.ProgrammingError: column ""..."" must appear in the GROUP BY clause or be used in an aggregate function...`

This is caused by the fix to ticket #19259. 

Queries with an aggregation now only list the PK field in the `GROUP BY` clause, but this doesn't work for views because they cannot have primary keys in PostgreSQL.

Now Django doesn't officially support views, or models without a primary key, but it did work before so it's somewhat of a regression.

I ran into this problem because I'm working on a legacy database and have models that are backed by a view using the `db_table` Meta option."	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	postgresql view aggregate annotate	Shai Berger Simon Charette Josh Smeaton olivier.tabone@…	Accepted	0	0	1	0	0	0
