i'm using postgresql 9.3 , django 1.7.4 psycopg2 2.5.4
the dba, asked create schema our application instead of using public.
we defined schema, , had add the
'options': { 'options': '-c search_path=custom-schema-name' }, to settings.
during testing, django creating test database corresponding name, can't set custom-schema name
i tried find way set custom schema name (i've read the docs) can't find way force creation of schema name during testing.
the error obtain
django.db.utils.programmingerror: no schema has been selected create in
when see created database , has schema public created default.
i partially solved issue , added search path schema name public
'options': { 'options': '-c search_path=custom-schema-name,public' }, but i'd create test database custom schema name.
does knows how set testing schema name ?
i ended writing custom test runner solve problem (using django 1.9.x):
myapp/test/runner.py
from types import methodtype django.test.runner import discoverrunner django.db import connections def prepare_database(self): self.connect() self.connection.cursor().execute(""" create schema foobar_schema authorization your_user; grant on schema foobar_schema your_user; """) class postgresschematestrunner(discoverrunner): def setup_databases(self, **kwargs): connection_name in connections: connection = connections[connection_name] connection.prepare_database = methodtype(prepare_database, connection) return super().setup_databases(**kwargs) settings.py
test_runner = 'myapp.test.runner.postgresschematestrunner'
Comments
Post a Comment