In my GeoDjango project I want to connect to a legacy PostgreSQL/PostGIS database. It contains the following schemas:

* data // contains all the geospatial data
* django // empty, created by me
* public // system tables such as `spatial_ref_sys`

I want the Django tables shown in the screenshot to go into the `django` schema. I do not want to pollute the `public` schema.

[![Django tables](https://i.stack.imgur.com/NrLzA.png)](https://i.stack.imgur.com/NrLzA.png)

I want the "data" models to connect to the `data` schema. I already tried to [generate models from the legacy tables](https://docs.djangoproject.com/en/1.8/howto/legacy-databases/) but `python manage.py inspectdb` connects to the `public` schema.

---

In order to provide access to the different schemas I adapted the [approach 2 of this article](http://blog.amvtek.com/posts/2014/Jun/13/accessing-multiple-postgres-schemas-from-django/) which preassigns individual `search_path` values to specific database users:

```
-- user accessing django schema...
CREATE ROLE django_user LOGIN PASSWORD 'secret';
ALTER ROLE django_user SET search_path TO django, public;

-- user accessing data schema...
CREATE ROLE data_user LOGIN PASSWORD 'secret';
ALTER ROLE data_user SET search_path TO data, public;

```

Then I configured the database connections as follows:

```
DATABASES = {

    'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'multi_schema_db',
            'USER': 'django_user',
            'PASSWORD': 'secret',
    },

    'data': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'multi_schema_db',
            'USER': 'data_user',
            'PASSWORD': 'secret',
    },
}

```

How can I actually configure that Django uses the `django` schema while "data" models connect to the `data` schema?

---

### Readings

* [How to use schemas in Django?](https://stackoverflow.com/questions/1160598/how-to-use-schemas-in-django)
* [How to specify schema name while running "syncdb" in django?](https://stackoverflow.com/questions/8680673/how-to-specify-schema-name-while-running-syncdb-in-django)
* [Issue #6148 - Add generic support for database schemas](https://code.djangoproject.com/ticket/6148#no2)