Haystack says “Model could not be found for SearchResult”

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 11:42:58

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!