Haystack says “Model could not be found for SearchResult”

后端 未结 2 1025
青春惊慌失措
青春惊慌失措 2021-01-01 23:26

After updating my Django from 1.7 to 1.9, search engine, which is based on Haystack and Solr, stopped working. This is what I get:

./manage.py shell
Python 2         


        
2条回答
  •  -上瘾入骨i
    2021-01-01 23:52

    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.

提交回复
热议问题