Changes between Initial Version and Version 1 of Ticket #35958


Ignore:
Timestamp:
Dec 1, 2024, 1:32:58 PM (2 weeks ago)
Author:
Tim Graham
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #35958

    • Property Summary Issue with the distinct() function when specifying a field to run it onQuerySet.distinct() crashes with "SELECT DISTINCT ON expressions must match initial ORDER BY expressions"
  • Ticket #35958 – Description

    initial v1  
    1 When I attempt to run the following code, I get a error.
     1When I attempt to run the following code, I get an error.
    22
    33Code:
    4 """
     4{{{#!python
    55user = User.objects.get(id=user_id)
    66list = List.objects.filter(user=user).order_by('email').distinct('email')
    7 """
     7}}}
    88
    99Error (Context: my app is called "lists"):
    10 """
     10{{{
    1111django.db.utils.ProgrammingError: SELECT DISTINCT ON expressions must match initial ORDER BY expressions
    1212LINE 1: SELECT COUNT(*) FROM (SELECT DISTINCT ON ("lists_list"...
    13 """
     13}}}
    1414
    15 I'm using a postgresql database and my list model is as follows:
    16 """
    17 class EventList(models.Model): # List for Marketting
     15I'm using a PostgreSQL database and my model is:
     16{{{#!python
     17class EventList(models.Model):
    1818    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
    1919    user= models.ForeignKey(User, on_delete=models.CASCADE)
    2020    email = models.EmailField()
    21 """
     21}}}
Back to Top