【发布时间】:2018-08-16 12:43:00
【问题描述】:
我正在尝试在运行 django 测试之前安装 hstore 扩展。为此,我重写了默认的 DiscoverRunner 的 setup_databases 方法。
但是,未安装扩展程序,测试显示此错误
django.db.utils.ProgrammingError: type "hstore" does not exist
这是我覆盖默认发现运行器的代码。
settings.py
TEST_RUNNER = 'project.tests.CustomDiscovererRunner'
tests.py
from django.db import DEFAULT_DB_ALIAS, connections
from django.test.runner import DiscoverRunner
class CustomDiscovererRunner(DiscoverRunner):
def setup_databases(self, **kwargs):
result = super().setup_databases(**kwargs)
connection = connections[DEFAULT_DB_ALIAS]
cursor = connection.cursor()
cursor.execute('CREATE EXTENSION IF NOT EXISTS HSTORE')
return result
【问题讨论】:
-
你用的是什么postgres、django和python版本?
-
一般来说你的方法应该有效...stackoverflow.com/questions/16355895/…
-
postgres 9.6 & python 3.5
标签: python django django-rest-framework django-testing django-tests