Changes between Initial Version and Version 1 of Ticket #35958
- Timestamp:
- Dec 1, 2024, 1:32:58 PM (18 hours ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #35958
- Property Summary Issue with the distinct() function when specifying a field to run it on → QuerySet.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.1 When I attempt to run the following code, I get an error. 2 2 3 3 Code: 4 """ 4 {{{#!python 5 5 user = User.objects.get(id=user_id) 6 6 list = List.objects.filter(user=user).order_by('email').distinct('email') 7 """ 7 }}} 8 8 9 9 Error (Context: my app is called "lists"): 10 """ 10 {{{ 11 11 django.db.utils.ProgrammingError: SELECT DISTINCT ON expressions must match initial ORDER BY expressions 12 12 LINE 1: SELECT COUNT(*) FROM (SELECT DISTINCT ON ("lists_list"... 13 """ 13 }}} 14 14 15 I'm using a postgresql database and my list model is as follows:16 """ 17 class EventList(models.Model): # List for Marketting15 I'm using a PostgreSQL database and my model is: 16 {{{#!python 17 class EventList(models.Model): 18 18 id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True) 19 19 user= models.ForeignKey(User, on_delete=models.CASCADE) 20 20 email = models.EmailField() 21 """ 21 }}}