2

I'm trying to develop a django interface for an existing postgresql db, the db makes use of various schemas, looking at the literature the following example should work, but it only returns the schema defined in the default database when I run python manaage.py inspectdb. Also when this works, how do I define which schema to use when defining the django model?

DATABASES = {

'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'OPTIONS' : {
            'options': '-c search_path=public'
        },
    'NAME': 'gygaia',
    'USER':'postgres',
    'PASSWORD':'abc',
    'HOST':'localhost',
    'PORT':'5432',
},

'samples': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'OPTIONS' : {
            'options': '-c search_path=samples'
        },
    'NAME': 'gygaia',
    'USER':'postgres',
    'PASSWORD':'abc',
    'HOST':'localhost',
    'PORT':'5432',
},
    'excavation': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'OPTIONS' : {
                'options': '-c search_path=excavation'
            },
        'NAME': 'gygaia',
        'USER':'postgres',
        'PASSWORD':'abc',
        'HOST':'localhost',
        'PORT':'5432',
    },
}
1

Here is a super easy project example with 2 apps and 3 schemes that cross each other with ForeignKey

https://github.com/mullerivan/DjangomultipleSchema
The idea is to define each model with the schema and table that need to use

class Meta:
    db_table = u'"app1\".\"on_app_one"'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.