diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index 99fc72e..0143770 100644
a
|
b
|
DATABASE_PASSWORD = '' # Not used with sqlite3.
|
130 | 130 | DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. |
131 | 131 | DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. |
132 | 132 | DATABASE_OPTIONS = {} # Set to empty dictionary for default. |
| 133 | DATABASE_SCHEMA = '' # Set to empty string for default. |
133 | 134 | |
134 | 135 | # Host for sending e-mail. |
135 | 136 | EMAIL_HOST = 'localhost' |
diff --git a/django/conf/project_template/settings.py b/django/conf/project_template/settings.py
index bbf005d..bb4564e 100644
a
|
b
|
DATABASE_USER = '' # Not used with sqlite3.
|
15 | 15 | DATABASE_PASSWORD = '' # Not used with sqlite3. |
16 | 16 | DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. |
17 | 17 | DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. |
| 18 | DATABASE_SCHEMA = '' # Set to empty string for default. |
18 | 19 | |
19 | 20 | # Local time zone for this installation. Choices can be found here: |
20 | 21 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name |
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 0a9ec1e..48d21eb 100644
a
|
b
|
class BaseDatabaseOperations(object):
|
290 | 290 | def prep_db_table(self, db_schema, db_table): |
291 | 291 | """ |
292 | 292 | Prepares and formats the table name if necessary. |
293 | | Just returns the db_table if not supported. |
| 293 | Just returns quoted db_table if not supported. |
294 | 294 | """ |
295 | | return db_table |
| 295 | return self.quote_name(db_table) |
| 296 | |
| 297 | def prep_db_index(self, db_schema, db_index): |
| 298 | """ |
| 299 | Prepares and formats the table index name if necessary. |
| 300 | Just returns quoted db_index if not supported. |
| 301 | """ |
| 302 | return self.quote_name(db_index) |
296 | 303 | |
297 | 304 | def random_function_sql(self): |
298 | 305 | """ |
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index 828889c..a7ab6fd 100644
a
|
b
|
class BaseDatabaseCreation(object):
|
274 | 274 | else: |
275 | 275 | tablespace_sql = '' |
276 | 276 | index_name = '%s_%s' % (model._meta.db_table, f.column) |
277 | | index_name = self.connection.ops.prep_db_table(model._meta.db_schema, index_name) |
| 277 | index_name = self.connection.ops.prep_db_index(model._meta.db_schema, index_name) |
278 | 278 | output = [style.SQL_KEYWORD('CREATE INDEX') + ' ' + |
279 | 279 | style.SQL_TABLE(index_name) + ' ' + |
280 | 280 | style.SQL_KEYWORD('ON') + ' ' + |
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index abea3b7..0d47dc0 100644
a
|
b
|
class DatabaseOperations(BaseDatabaseOperations):
|
167 | 167 | else: |
168 | 168 | return qn(db_table) |
169 | 169 | |
| 170 | def prep_db_index(self, db_schema, db_index): |
| 171 | return self.prep_db_table(db_schema, db_index) |
| 172 | |
170 | 173 | def random_function_sql(self): |
171 | 174 | return 'RAND()' |
172 | 175 | |
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index f1240d7..7488376 100644
a
|
b
|
WHEN (new.%(col_name)s IS NULL)
|
135 | 135 | else: |
136 | 136 | return qn(db_table) |
137 | 137 | |
| 138 | def prep_db_index(self, db_schema, db_index): |
| 139 | return self.prep_db_table(db_schema, db_index) |
| 140 | |
138 | 141 | def prep_for_iexact_query(self, x): |
139 | 142 | return x |
140 | 143 | |
diff --git a/django/db/models/options.py b/django/db/models/options.py
index a6fd925..7985e5f 100644
a
|
b
|
class Options(object):
|
30 | 30 | self.module_name, self.verbose_name = None, None |
31 | 31 | self.verbose_name_plural = None |
32 | 32 | self.db_table = '' |
33 | | self.db_schema = '' |
| 33 | self.db_schema = settings.DATABASE_SCHEMA |
34 | 34 | self.qualified_name = '' |
35 | 35 | self.ordering = [] |
36 | 36 | self.unique_together = [] |
diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt
index 30b6fb6..682a229 100644
a
|
b
|
If your database table name is an SQL reserved word, or contains characters that
|
50 | 50 | aren't allowed in Python variable names -- notably, the hyphen -- that's OK. |
51 | 51 | Django quotes column and table names behind the scenes. |
52 | 52 | |
| 53 | .. _db_schema: |
| 54 | |
53 | 55 | ``db_schema`` |
54 | 56 | ----------------- |
55 | 57 | |
| 58 | .. attribute:: Options.db_schema |
| 59 | |
56 | 60 | **New in Django development version** |
57 | 61 | |
58 | 62 | The name of the database schema to use for the model. If the backend |
59 | 63 | doesn't support multiple schemas, this options is ignored. |
60 | 64 | |
61 | | If this is used Django will prefix any table names with the schema name. |
62 | | For example MySQL Django would use ``db_schema + '.' + db_table``. |
63 | | Be aware that postgres supports different schemas within the database. |
| 65 | If this is used the Django will prefix the model table names with the schema |
| 66 | name. For example MySQL Django would use ``db_schema + '.' + db_table``. |
| 67 | Be aware that PostgreSQL supports different schemas within the database. |
64 | 68 | MySQL solves the same thing by treating it as just another database. |
65 | 69 | |
66 | 70 | |
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
index e8c673d..4c16bf7 100644
a
|
b
|
Default: ``''`` (Empty string)
|
227 | 227 | The port to use when connecting to the database. An empty string means the |
228 | 228 | default port. Not used with SQLite. |
229 | 229 | |
| 230 | .. setting:: DATABASE_SCHEMA |
| 231 | |
| 232 | DATABASE_SCHEMA |
| 233 | --------------- |
| 234 | |
| 235 | **New in Django development version** |
| 236 | |
| 237 | Default: ``''`` (Empty string) |
| 238 | |
| 239 | The name of the database schema to use for models. If the backend |
| 240 | doesn't support multiple schemas, this options is ignored. An empty |
| 241 | string means the default schema. |
| 242 | |
| 243 | If this is used the Django will prefix any table names with the schema name. |
| 244 | The schema can be overriden in model, for details see :ref:`db_schema`. |
| 245 | |
230 | 246 | .. setting:: DATABASE_USER |
231 | 247 | |
232 | 248 | DATABASE_USER |