1

I have a Django app that I need to connect to a schema "new_schema" by default, rather than public. I've managed to get this working on my local instance by running

CREATE SCHEMA new_schema;

on the local database & then adding into my settings a database config like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'OPTIONS': {
            'options': '-c search_path=new_schema',
        },
        'NAME': 'database_name',
        'USER': 'user_name',
        'PASSWORD': 'password',
        'HOST': 'db',
        'PORT': '5432',
    },
}

But, when I deploy to Heroku & create the schema there, I can't get the app to point to the new schema. In my production settings file, I have

DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)
DATABASES['default']['OPTIONS']['options'] = '-c search_path=new_schema'

in order to get the Heroku database url into the right config format, and then add in my schema to the options. But for some reason this doesn't work - instead any migrations get applied to public as do db queries.

I can explicitly set the new_schema in the Postgres users search_path, but there are other servers that need different default schemas

I have been going in circles trying to resolve this for ages, I don't know what I'm missing! I can' tell if this is a problem with my Heroku/Postgres setup, or my Django app.

be2213444
  • 607
  • 1
  • 4
  • 10

0 Answers0