patternsqldjangoMinor
Django postgres multiple schema
Viewed 0 times
multipledjangoschemapostgres
Problem
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',
},
}Solution
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
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"'Code Snippets
class Meta:
db_table = u'"app1\".\"on_app_one"'Context
StackExchange Database Administrators Q#208826, answer score: 6
Revisions (0)
No revisions yet.