Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify schema name while running "syncdb" in django?

Assuming I have a schema with the name "my_schema", how can I create tables with "django syncdb" for that particular schema? Or is there any other alternatives for quickly creating tables from my django models? I think, by default django creates tables for the "public" schema.

like image 528
Devasia Joseph Avatar asked Dec 30 '11 14:12

Devasia Joseph


People also ask

What is schema in Django?

API schemas are a useful tool that allow for a range of use cases, including generating reference documentation, or driving dynamic client libraries that can interact with your API. Django REST Framework provides support for automatic generation of OpenAPI schemas.

Which of the file in Django contains database schema?

Django's inspectdb feature uses the information_schema database, which contains detailed data on all database schemas.


1 Answers

First, you must have psycopg2>=2.4.3 [1]. If you have then you can add schema to OPTIONS in dictionary-based database configuration, like this:

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

Tested on postgresql 8.4 and django 1.3

  1. http://initd.org/psycopg/docs/module.html?highlight=connect#psycopg2.connect
  2. http://www.postgresql.org/docs/8.4/static/libpq-connect.html#LIBPQ-CONNECT-OPTIONS
like image 185
rombarcz Avatar answered Nov 16 '22 23:11

rombarcz