﻿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
35958	"QuerySet.distinct() crashes with ""SELECT DISTINCT ON expressions must match initial ORDER BY expressions"""	adofosam		"When I attempt to run the following code, I get an error.

Code:
{{{#!python
user = User.objects.get(id=user_id)
list = List.objects.filter(user=user).order_by('email').distinct('email')
}}}

Error (Context: my app is called ""lists""):
{{{
django.db.utils.ProgrammingError: SELECT DISTINCT ON expressions must match initial ORDER BY expressions
LINE 1: SELECT COUNT(*) FROM (SELECT DISTINCT ON (""lists_list""...
}}}

I'm using a PostgreSQL database and my model is:
{{{#!python
class EventList(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
    user= models.ForeignKey(User, on_delete=models.CASCADE)
    email = models.EmailField()
}}}"	Bug	new	Database layer (models, ORM)	5.1	Normal		distinct		Unreviewed	0	0	0	0	0	0
