3

I am using haystack with elasticsearch. I have build index data using rebuild_index command. But when I tried to search for object, its giving me following error:

"Object could not be found in database for SearchResult ' (pk=u'118')>'."

I have double checked in database, no records were deleted. But I am still getting this error.

Can anyone please help with it?

Thanks.

Nikhil N
  • 4,507
  • 1
  • 35
  • 53

3 Answers3

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))
Chris Montanaro
  • 16,948
  • 4
  • 20
  • 29
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.

Nikhil N
  • 4,507
  • 1
  • 35
  • 53
  • Check your database config, also below answer from Chris. – Nikhil N May 21 '17 at 08:13
  • Thanks for the reply! Finally I realised the reason is that the search index dump of my development database isn't compatible with the one of the production database. I shouldn't have included the index dump to VCS. – nalzok May 21 '17 at 08:34
  • ohh ok, glad you figure out. – Nikhil N May 21 '17 at 10:44
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
  • 2,848
  • 1
  • 20
  • 27