当 haystack 尝试导入多语言模型时,由于导入错误而无法使用 django 管理命令
我正在使用 django-haystack 在我的网站上进行搜索。 我还在 I18n 中使用 django 多语言模型。 我在 search_indexes.py 中导入 MultilingualModel,
只要 INSTALLED_APPS 中没有 haystack,我就可以运行所有管理命令。
当 haystack 位于 INSTALLED_APPS 中并尝试运行syncdb或migrate(以及其他几个管理命令)时,我总是得到:
django.core.exceptions.ImproperlyConfigured: ImportError haystack: cannot import name MultilingualModel
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能与
haystack.autodiscover()
中进行的黑客攻击有关。此行为记录在此处: http ://docs.haystacksearch.org/dev/debugging.html#import-errors-on-start-up-mentioning-handle-registrations 这张票中有一个很长的讨论:https://github.com/toastdriven/django-haystack/issues/84简而言之,将 haystack.autodiscover() 移动到您的 urls.py 有时可以解决此问题。在运行syncdb或migrate时设置
HAYSTACK_ENABLE_REGISTRATIONS = False
已经为我解决了这个问题,在我的settings.py
中使用此代码段: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/84The long and short if it is that moving
haystack.autodiscover()
into yoururls.py
can sometimes resolve this issue. SettingHAYSTACK_ENABLE_REGISTRATIONS = False
when running syncdb or migrate has resolved this for me using this snippet in mysettings.py
:除非 haystack 位于
INSTALLED_APPS
中,否则search_indexes.py
不会被处理。一般来说,问题在于MultilingualModel
的导入。要么它没有真正安装在您的环境中(尝试从普通 python shell 导入它),要么您导入错误(例如,它实际上在另一个模块中)。一旦您可以从 python shell 成功导入
MultilingualModel
,您就不会有任何问题。search_indexes.py
doesn't get processed unless haystack is inINSTALLED_APPS
. The problem is with the import ofMultilingualModel
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.