Django won't use postgres schema properly

Viewed 340

I have a problem with using schema while running tests with django.
All tables in my postgres database are in schema, let's name it 'schema'. In my settings.py i added:

    'OPTIONS': {
        'options': '-c search_path=schema',
        'connect_timeout': 5,
    },

to tell django to use 'schema' schema.
All production code is working perfectly.

Problem is:
When i added DB testing and run

python manage.py test

it resulted with

django.db.utils.ProgrammingError: no schema has been selected to create in

I tried to remove schema-line from settings.py and add 'schema.' at the beginning of every db_table name in models.py.
It worked for tests, but now when i run my production code, it ends up with:

django.db.utils.ProgrammingError: relation "schema.table" does not exist

How can i tell manage.py to create db with schema, so i don't have to modify models.py or settings.py?
Or how can i properly add usage of my schema in models.py ?

0 Answers
Related