I've installed the hstore extension successfully, and everything works when I syncdb
. (I'm using djorm-ext-hstore)
However, nose creates a new temp database to run tests in, and hstore is not installed in it.
I need to run CREATE EXTENSION HSTORE;
on the test db right before nose syncs the db, but I can't find any info on how to do that.
Any ideas?
This is a non-issue: The best way to fix this is to apply the hstore extension on the default database, template1
psql -d template1 -c 'create extension hstore;'
Reference: How to create a new database with the hstore extension already installed?
With Django 1.8 (which is outdated now, but it still exists in 3.2):
from django.contrib.postgres.operations import HStoreExtension
class Migration(migrations.Migration):
...
operations = [
HStoreExtension(),
...
]
https://docs.djangoproject.com/en/3.2/ref/contrib/postgres/fields/#hstorefield
EDIT: Just note that there is also a JSONField which handles (un)marshalling of json already and inline search. The HStoreExtension is not necessary for it. Requires Django >=1.11 and Postgres >=9.4.
I'm assuming you're using django-nose. In this case you should create your own 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
Then in settings.py
you should specify your custom test runner:
TEST_RUNNER = 'path.to.my.module.MyTestSuiteRunner'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With