gpt4 book ai didi

Django 全文搜索 : says unaccent does not exist

转载 作者:行者123 更新时间:2023-11-29 12:24:23 26 4
gpt4 key购买 nike

我正在使用 Django 2.0 和 postgresql 9.6

我已经在我的应用程序(文章)中创建并清空了迁移文件,其中包含以下内容以添加 unaccent 和 trigram 扩展

# Generated by Django 2.0 on 2018-02-06 22:34

from django.db import migrations
from django.contrib.postgres.operations import UnaccentExtension, TrigramExtension


class Migration(migrations.Migration):

dependencies = [
('articles', '0012_auto_20180205_2234'),
]

operations = [
UnaccentExtension(),
TrigramExtension()
]

然后我尝试运行以下查询:

from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector
vector = SearchVector('title',config='unaccent', weight='A') + SearchVector('description',config='unaccent', weight='B')
query = SearchQuery('india')
Article.objects.annotate(rank=SearchRank(vector, query)).filter(rank__gte=0.3).order_by('rank')

ProgrammingError: text search configuration "unaccent" does not exist
LINE 1: ...rticle"."qa_bool", ts_rank((setweight(to_tsvector('unaccent'...

最佳答案

我认为您的迁移文件没有在您的数据库中创建指定的 PostgreSQL 扩展。

也许您的数据库用户没有 super 用户权限。

Django 文档在 Creating extension using migrations 部分对其进行了解释:

Creating the extension requires a database user with superuser privileges. If the Django database user doesn’t have superuser privileges, you’ll have to create the extension outside of Django migrations with a user that has the appropriate privileges. In that case, connect to your Django database and run the query CREATE EXTENSION IF NOT EXISTS hstore;

更新

我再次阅读了您的代码,我认为问题在于 config='unaccent' 您不能将 unaccent 用作配置,但您必须传递一种语言 ( es: '意大利语') 或 '简单'

关于Django 全文搜索 : says unaccent does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48656231/

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