2024-04-29 10:41:25 发布
网友
我已经成功地安装了hstore扩展,当我syncdb时一切都正常。(我正在使用djorm-ext-hstore)
syncdb
但是,nose创建了一个新的temp数据库来运行测试,其中没有安装hstore。在
在nose同步数据库之前,我需要在testdb上运行CREATE EXTENSION HSTORE;,但是我找不到任何关于如何实现这一点的信息。在
CREATE EXTENSION HSTORE;
有什么想法吗?在
这不是问题:解决这个问题的最佳方法是在默认数据库上应用hstore扩展template1
template1
psql -d template1 -c 'create extension hstore;'
参考号:How to create a new database with the hstore extension already installed?
我假设你用的是django-nose。在这种情况下,您应该创建自己的TestSuiteRunner:
TestSuiteRunner
from django.db import connections, DEFAULT_DB_ALIAS from django_nose import NoseTestSuiteRunner class MyTestSuiteRunner(NoseTestSuiteRunner): def setup_databases(self): result = super(MyTestSuiteRunner, self).setup_databases() connection = connections[DEFAULT_DB_ALIAS] cursor = connection.cursor() cursor.execute('CREATE EXTENSION HSTORE') return result
然后在settings.py中,您应该指定您的自定义测试运行程序:
settings.py
使用Django 1.8:
from django.contrib.postgres.operations import HStoreExtension class Migration(migrations.Migration): ... operations = [ HStoreExtension(), ... ]
https://docs.djangoproject.com/en/1.8/ref/contrib/postgres/fields/#hstorefield
编辑:请注意还有一个JSONField,它处理(取消)json的编组和内联搜索。它不需要HStoreExtension。要求Django>;=1.11和Postgres>;=9.4。在
这不是问题:解决这个问题的最佳方法是在默认数据库上应用hstore扩展
template1
psql -d template1 -c 'create extension hstore;'
参考号:How to create a new database with the hstore extension already installed?
我假设你用的是django-nose。在这种情况下,您应该创建自己的
TestSuiteRunner
:然后在
^{pr2}$settings.py
中,您应该指定您的自定义测试运行程序:使用Django 1.8:
https://docs.djangoproject.com/en/1.8/ref/contrib/postgres/fields/#hstorefield
编辑:请注意还有一个JSONField,它处理(取消)json的编组和内联搜索。它不需要HStoreExtension。要求Django>;=1.11和Postgres>;=9.4。在
相关问题 更多 >
编程相关推荐