[Fixed]-Haystack says “Model could not be found for SearchResult”

6👍

I was able to fix the issue by including a missing commit to the 2.4.1 release. The commit that fixed this issue was https://github.com/django-haystack/django-haystack/commit/f1ed18313777005dd77ed724ecbfb27c0b03cad8

so you can do

pip install git+ssh://git@github.com/django-haystack/django-haystack.git@f1ed18313777005dd77ed724ecbfb27c0b03cad8

to install until that specific commit.

1👍

It would be good to start checking the app registry to make sure it can find your model (just to be sure).

from django.apps import apps as django_apps
model = django_apps.get_model('mediainfo.artist')
model.app_label, model.model_name
assert model._meta.app_label == 'mediainfo'
assert model._meta.model_name == 'artist'

Then I would check what haystack is returning.

from haystack.utils.app_loading import haystack_get_model
haystack_model = haystack_get_model('mediainfo', 'artist')
haystack_model == model

If that doesn’t return the same thing (haystack_model != model); then you will need to dig further.

However, loading and looking up models changed between django 1.7.0 and 1.8.0 (deprecation), and django.db.models.loading.get_model was removed in 1.8.2.
Details on django-haystack #1206.

Therefore, for django-haystack to work with django 1.9.0 you need a release that includes this commit; that is to say django-haystack>=2.4.0.

👤dnozay

Leave a comment