gpt4 book ai didi

django-haystack - 将新字段添加到索引后更新索引导致错误

转载 作者:行者123 更新时间:2023-12-02 01:32:14 26 4
gpt4 key购买 nike

我有一个 django 站点,它使用 Haystack 和 Xapian 后端进行搜索索引。我已向正在索引的模型之一添加了一个新字段,然后将该字段添加到该模型的 SearchIndex 中。我跑过:

python manage.py update_index

要更新索引,但出现以下错误:

Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django_haystack-1.0.1_final-py2.6.egg/haystack/management/commands/update_index.py", line 51, in handle
self.handle_app(None, **options)
File "/usr/local/lib/python2.6/dist-packages/django_haystack-1.0.1_final-py2.6.egg/haystack/management/commands/update_index.py", line 107, in handle_app
index.backend.update(index, small_cache_qs[start:end])
File "/usr/local/lib/python2.6/dist-packages/xapian_haystack-1.1.3beta-py2.6.egg/xapian_backend.py", line 204, in update
data = index.prepare(obj)
File "/usr/local/lib/python2.6/dist-packages/django_haystack-1.0.1_final-py2.6.egg/haystack/indexes.py", line 102, in prepare
self.prepared_data[field_name] = field.prepare(obj)
File "/usr/local/lib/python2.6/dist-packages/django_haystack-1.0.1_final-py2.6.egg/haystack/fields.py", line 119, in prepare
return self.convert(super(CharField, self).prepare(obj))
File "/usr/local/lib/python2.6/dist-packages/django_haystack-1.0.1_final-py2.6.egg/haystack/fields.py", line 75, in prepare
raise SearchFieldError("The model '%s' has an empty model_attr '%s' and doesn't allow a default or null value." % (repr(current_object), attr))
haystack.exceptions.SearchFieldError: The model 'None' has an empty model_attr 'address_county' and doesn't allow a default or null value.

我使用的版本是 django 1.2 和 django-haystack 1.0.1。目前我无法将它们升级到最新版本。

最佳答案

我找到了答案。线索就在错误消息中(众所周知,这种情况并不总是发生!):

The model 'None' has an empty model_attr 'address_county' and doesn't allow a default or null value.

我的模型字段是使用 blank=True, null=True 创建的。这导致了错误,所以我删除了这些并添加了 default='' ,这使我能够毫无错误地更新索引。希望这对某人有帮助!

关于django-haystack - 将新字段添加到索引后更新索引导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8486816/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com