Forums

Postgresql issue with Django, can't select the first item for all many-to-one field model queries

I migrated my database from sqlite3 to psql recently, using psql server just on pythonanywhere. But I just found that there is an issue selecting the first model. Here is the detail

post_1.images.all()[0].image should return <ImageFieldFile: forum/kyttndr/1234567/asap.jpg> but it actually returned the last object. I don't see this issue for sqlite3 database. Can someone help me get through this?

django does not guarantee ordering when you do django queries (eg: with .all()).

for the negative indexing stuff, django has a .first() and a .last()