has more than one 'SearchIndex`` handling it

原创 赤水  2016年6月14日 02:24 阅读 209 次
在 使用 whoosh 做内容检索时,报错如下:has more than one 'SearchIndex`` handling it,不只有一个 SearchIndex,提示很明确了,但是在处理这个问题时,忽略了pyc 所有处理这个问题废很长时间,在这里做个记录
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.9.2-py2.7.egg/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/Django-1.9.2-py2.7.egg/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.9.2-py2.7.egg/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.9.2-py2.7.egg/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/haystack/management/commands/rebuild_index.py", line 25, in handle
    call_command('clear_index', **options)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.9.2-py2.7.egg/django/core/management/__init__.py", line 120, in call_command
    return command.execute(*args, **defaults)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.9.2-py2.7.egg/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/haystack/management/commands/clear_index.py", line 56, in handle
    backend.clear(commit=self.commit)
  File "/usr/local/lib/python2.7/dist-packages/haystack/backends/whoosh_backend.py", line 243, in clear
    self.setup()
  File "/usr/local/lib/python2.7/dist-packages/haystack/backends/whoosh_backend.py", line 130, in setup
    self.content_field_name, self.schema = self.build_schema(connections[self.connection_alias].get_unified_index().all_searchfields())
  File "/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py", line 332, in all_searchfields
    self.build()
  File "/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py", line 222, in build
    model, self._indexes[model], index
django.core.exceptions.ImproperlyConfigured: Model '<class 'Project.models.TestModel'>' has more than one 'SearchIndex`` handling it. Please exclude either '<Book.search_indexes.NoteIndex object at 0x7efc5fd7ea78>' or '<Project.search_indexes.NoteIndex object at 0x7efc5fd9a808>' using the 'EXCLUDED_INDEXES' setting defined in 'settings.HAYSTACK_CONNECTIONS'.

#完整search_indexes.py

cat Project/search_indexes.py
#coding=utf-8
from haystack import indexes
from Project.models import TestModel

class NoteIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)  #必须
    subject = indexes.CharField(model_attr='subject')  

    def get_model(self):
        return TestModel

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

 

出现这种错误是一个项目中有 2个这样的文件search_indexes.py 如果只找到一个search_indexes.py,尝试找找有没有search_indexes.pyc 文件

本文地址: https://blog.lssin.com/readblog/110.html
版权声明:本文为原创文章,版权归  赤水 所有,欢迎分享本文,转载请保留出处!

发表评论


表情