python - 在 Django 1.10 中使用 Postgres 搜索时出现 NotImplementedError

标签 python django postgresql

我正在使用 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 后端取代。

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

最佳答案

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

关于python - 在 Django 1.10 中使用 Postgres 搜索时出现 NotImplementedError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38943668/

相关文章:

django - 如何在 Django Postgres 表文本区域字段中搜索多个单词?

sql - 使用varchar类型代替char类型可以避免哪些比较问题?

python - 以列表形式阅读列

python - 模拟抛硬币实验 - RealPython

python - 在 POST Django 上加密密码

python - django url 中的 '_' 有什么作用?

sql - 使用计算的时间戳设置 "VALID UNTIL"值

java - Mapstruct:尝试映射嵌入对象内的字段时返回 null

python - 跨多个操作系统的 df 命令

python - ROS 从 python 节点发布数组