Can't use django management commands because of Import Errors when haystack tries to import multiligualmodel

不羁岁月 提交于 2019-12-08 04:26:07

问题


I'm using django-haystack for searching on my site. I'm also using django multilingual model for I18n. I import MultilingualModel in search_indexes.py

I ca run all manangement commands as long as I don't have haystack in the INSTALLED_APPS.

When haystack is in the INSTALLED_APPS and try to run syncdb or migrate (and several other management commands) I'm always getting:

django.core.exceptions.ImproperlyConfigured: ImportError haystack: cannot import name MultilingualModel

回答1:


This is likely related to the hacks done in haystack.autodiscover(). This behavior is documented here: http://docs.haystacksearch.org/dev/debugging.html#import-errors-on-start-up-mentioning-handle-registrations There is a long discussion in this ticket: https://github.com/toastdriven/django-haystack/issues/84

The long and short if it is that moving haystack.autodiscover() into your urls.py can sometimes resolve this issue. Setting HAYSTACK_ENABLE_REGISTRATIONS = False when running syncdb or migrate has resolved this for me using this snippet in my settings.py:

# FIXME: This is a complete hack to get around circular imports in 
# django-haystack and other apps such as django-endless-pagination
SKIP_COMMANDS = ['syncdb', 'migrate', 'schemamigration', 'datamigration']
if any([command in sys.argv for command in SKIP_COMMANDS]):
    HAYSTACK_ENABLE_REGISTRATIONS = False



回答2:


search_indexes.py doesn't get processed unless haystack is in INSTALLED_APPS. The problem is with the import of MultilingualModel in general. Either it's not truly installed in your environment (attempt to import it from a vanilla python shell), or you have the import wrong (it's actually in another module, for example).

Once you can successfully import MultilingualModel from a python shell, you won't have any problems.



来源:https://stackoverflow.com/questions/8577449/cant-use-django-management-commands-because-of-import-errors-when-haystack-trie

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