Without changing the code and updating, the display order of pictures on my production server(django,postgresql,bootstrap,nginx,uwsgi) has changed(see the picture).
I can't reproduce this problem on my local server with same backup/code...
In Django ORM I have this result:
- local:
Car.objects.filter(model=1)
<QuerySet [<CarImage: 1>, <CarImage: 2>, <CarImage: 3>]>
- production:
Car.objects.filter(model=1)
<QuerySet [<CarImage: 3>, <CarImage: 2>, <CarImage: 1>]>
Reboot nginx/postgresql didn't help. What could have happened and how to fix it?
CodePudding user response:
The ordering is done at DB level so if you are not using the same DB engine the results might differ, to fix the issue just do that :
Car.objects.filter(model=1).order_by("pk")
or
Car.objects.filter(model=1).order_by("-pk")
From the documentation :
if a query doesn’t have an ordering specified, results are returned from the database in an unspecified order. A particular