【问题标题】:NotImplementedError when using Postgres search in Django 1.10在 Django 1.10 中使用 Postgres 搜索时出现 NotImplementedError
【发布时间】:2016-08-14 15:25:41
【问题描述】:

我正在使用 Django 1.10 提供的 Postgres 全文搜索并得到 NotImplementedError。我使用的搜索查询是:

Application.objects.filter(applicant_data__search='test')

错误是:

NotImplementedError: Add 'django.contrib.postgres' to settings.INSTALLED_APPS to use the search operator.

我的 INSTALLED_APPS 设置包括 django.contrib.postgres:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
'main',
] 

我正在为我的数据库引擎使用 psycopg2:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'dbname',
    'USER': 'username',
    'PASSWORD': '',
    'HOST': 'localhost',
}
}

我的模型是:

class Application(models.Model):
    applicant_data = JSONField()

当我从 django shell 运行 get_app_config 时,postgres 应用程序返回正确的值:

from django.apps import apps
apps.get_app_config('postgres').name
'django.contrib.postgres'

抛出 NotImplementedError 的函数是来自 django.db.backends.postgres 的 fulltext_search_sql,所以我的猜测是 django.contrib.postgres 要么没有正确加载,要么被默认的 django postgres 后端替换。

不知道从哪里开始,有人有类似的问题和/或见解吗?

【问题讨论】:

    标签: python django postgresql


    【解决方案1】:

    找出这个错误的原因 - 全文搜索运算符不适用于 JSON 字段。

    【讨论】:

    • 这仍然是个问题吗?
    猜你喜欢
    • 2017-03-31
    • 1970-01-01
    • 2016-05-09
    • 1970-01-01
    • 2019-06-22
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多