#28774 closed Uncategorized (duplicate)
Use only a specific database schema instead of 'public' one (like in Postgresql)
Reported by: | Riccardo Campisano | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8 |
Severity: | Normal | Keywords: | django, orm, database, postgresql, schema |
Cc: | riccardo.campisano@…, ogando@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hello,
In our project (https://github.com/desihub/qlf) we should use a PostgreSQL database used by others application, so that we want to configure Django ORM to use just a specific schema.
I cannot find such kind of configurations in the official documentation. A tip for a kind of such configuration is available in
https://www.amvtek.com/blog/posts/2014/Jun/13/accessing-multiple-postgres-schemas-from-django/
and it appears to work, using a specific config like that
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'OPTIONS': { 'options': '-c search_path=qlf_schema' }, },
However, I would be sure that this is the correct (official, supported) way to do such thing, and that will be supported in the future (and that this is not a workaround that currently work but can break in a next version of Django).
Thanks,
Riccardo
Official support for database schemas is discussed in #6148.
I think the
'-c search_path=qlf_schema'
method you mentioned uses a psycopg2 configuration option and I wouldn't expect that to stop working unless psycopg2 changes it.