[Django]-Object could not be found in database for SearchResult django haystack

3👍

Answering it to mark it resolved.

It was database config issue. I am having different settings file for different environment, and was having mismatch for database config in both files.

3👍

It looks like you are searching for your pk as a string and not an integer, not sure what your query looks like.

as integer, notice no quotes when defining pk_int:

pk_int = 118 
Model.objects.get(pk = pk_int)

if your variable containing the pk is a string already, use int():

pk_string = '118'
Model.objects.get(pk = int(pk_string))

0👍

For anyone coming from a web search engine, if the accepted answer doesn’t work for you, you can also try rebuilding the index:

./manage.py rebuild_index

I had the same error message as the OP, and rebuilding the index solved my issue.

👤Lual

Leave a comment