How to specify a schema name when running "syncdb" in django?

Assuming I have a schema named "my_schema", how do I create tables with "django syncdb" for this particular schema? Or are there other alternatives for quickly creating tables from my django models? I think by default django creates tables for the "public" schema.

+7
source share
2 answers

First you should have psycopg2> = 2.4.3 [1]. If you have, you can add a schema to OPTIONS in a dictionary-based database, for example:

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', # ... 'OPTIONS': { 'options': '-c search_path=my_schema' } } } 

Tested on postgresql 8.4 and django 1.3

+5
source

I used the following information and work for me

'default': {"ENGINE": 'django.db.backends.postgresql_psycopg2', 'NAME': 'dab_name', "USER": "username", "PASSWORD": "password", "HOST": "localhost "," PORT ":" 5432 ", 'OPTIONS': {'options': '-c search_path = tours' #schema name}}

Tested on postgresql 9 and django 1.10.2

Thanks @romke

0
source

All Articles