5 Django attempts to support as many features as possible on all database
6 backends. However, not all database backends are alike, and we've had to make
7 design decisions on which features to support and which assumptions we can make
10 This file describes some of the features that might be relevant to Django
11 usage. Of course, it is not intended as a replacement for server-specific
12 documentation or reference manuals.
19 .. versionchanged:: 1.4
21 Django supports PostgreSQL 8.2 and higher.
23 PostgreSQL 8.2 to 8.2.4
24 -----------------------
26 The implementation of the population statistics aggregates ``STDDEV_POP`` and
27 ``VAR_POP`` that shipped with PostgreSQL 8.2 to 8.2.4 are `known to be
28 faulty`_. Users of these releases of PostgreSQL are advised to upgrade to
29 `Release 8.2.5`_ or later. Django will raise a ``NotImplementedError`` if you
30 attempt to use the ``StdDev(sample=False)`` or ``Variance(sample=False)``
31 aggregate with a database backend that falls within the affected release range.
33 .. _known to be faulty: http://archives.postgresql.org/pgsql-bugs/2007-07/msg00046.php
34 .. _Release 8.2.5: http://www.postgresql.org/docs/devel/static/release-8-2-5.html
36 Optimizing PostgreSQL's configuration
37 -------------------------------------
39 Django needs the following parameters for its database connections:
41 - ``client_encoding``: ``'UTF8'``,
42 - ``default_transaction_isolation``: ``'read committed'``,
43 - ``timezone``: ``'UTC'`` when :setting:`USE_TZ` is ``True``, value of
44 :setting:`TIME_ZONE` otherwise.
46 If these parameters already have the correct values, Django won't set them for
47 every new connection, which improves performance slightly. You can configure
48 them directly in :file:`postgresql.conf` or more conveniently per database
49 user with `ALTER ROLE`_.
51 Django will work just fine without this optimization, but each new connection
52 will do some additional queries to set these parameters.
54 .. _ALTER ROLE: http://www.postgresql.org/docs/current/interactive/sql-alterrole.html
59 :doc:`By default </topics/db/transactions>`, Django runs with an open
60 transaction which it commits automatically when any built-in, data-altering
61 model function is called. The PostgreSQL backends normally operate the same as
62 any other Django backend in this respect.
64 .. _postgresql-autocommit-mode:
69 If your application is particularly read-heavy and doesn't make many
70 database writes, the overhead of a constantly open transaction can
71 sometimes be noticeable. For those situations, you can configure Django
72 to use *"autocommit"* behavior for the connection, meaning that each database
73 operation will normally be in its own transaction, rather than having
74 the transaction extend over multiple operations. In this case, you can
75 still manually start a transaction if you're doing something that
76 requires consistency across multiple database operations. The
77 autocommit behavior is enabled by setting the ``autocommit`` key in
78 the :setting:`OPTIONS` part of your database configuration in
79 :setting:`DATABASES`::
85 In this configuration, Django still ensures that :ref:`delete()
86 <topics-db-queries-delete>` and :ref:`update() <topics-db-queries-update>`
87 queries run inside a single transaction, so that either all the affected
88 objects are changed or none of them are.
90 .. admonition:: This is database-level autocommit
92 This functionality is not the same as the :ref:`autocommit
93 <topics-db-transactions-autocommit>` decorator. That decorator is
94 a Django-level implementation that commits automatically after
95 data changing operations. The feature enabled using the
96 :setting:`OPTIONS` option provides autocommit behavior at the
97 database adapter level. It commits after *every* operation.
99 If you are using this feature and performing an operation akin to delete or
100 updating that requires multiple operations, you are strongly recommended to
101 wrap you operations in manual transaction handling to ensure data consistency.
102 You should also audit your existing code for any instances of this behavior
103 before enabling this feature. It's faster, but it provides less automatic
104 protection for multi-call operations.
106 Indexes for ``varchar`` and ``text`` columns
107 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109 When specifying ``db_index=True`` on your model fields, Django typically
110 outputs a single ``CREATE INDEX`` statement. However, if the database type
111 for the field is either ``varchar`` or ``text`` (e.g., used by ``CharField``,
112 ``FileField``, and ``TextField``), then Django will create
113 an additional index that uses an appropriate `PostgreSQL operator class`_
114 for the column. The extra index is necessary to correctly perfrom
115 lookups that use the ``LIKE`` operator in their SQL, as is done with the
116 ``contains`` and ``startswith`` lookup types.
118 .. _PostgreSQL operator class: http://www.postgresql.org/docs/8.4/static/indexes-opclass.html
125 Django expects the database to support transactions, referential integrity, and
126 Unicode (UTF-8 encoding). Fortunately, MySQL_ has all these features as
127 available as far back as 3.23. While it may be possible to use 3.23 or 4.0,
128 you'll probably have less trouble if you use 4.1 or 5.0.
133 `MySQL 4.1`_ has greatly improved support for character sets. It is possible to
134 set different default character sets on the database, table, and column.
135 Previous versions have only a server-wide character set setting. It's also the
136 first version where the character set can be changed on the fly. 4.1 also has
137 support for views, but Django currently doesn't use views.
142 `MySQL 5.0`_ adds the ``information_schema`` database, which contains detailed
143 data on all database schema. Django's ``inspectdb`` feature uses this
144 ``information_schema`` if it's available. 5.0 also has support for stored
145 procedures, but Django currently doesn't use stored procedures.
147 .. _MySQL: http://www.mysql.com/
148 .. _MySQL 4.1: http://dev.mysql.com/doc/refman/4.1/en/index.html
149 .. _MySQL 5.0: http://dev.mysql.com/doc/refman/5.0/en/index.html
151 .. _mysql-storage-engines:
156 MySQL has several `storage engines`_ (previously called table types). You can
157 change the default storage engine in the server configuration.
159 Until MySQL 5.5.4, the default engine was MyISAM_ [#]_. The main drawbacks of
160 MyISAM are that it doesn't support transactions or enforce foreign-key
161 constraints. On the plus side, it's currently the only engine that supports
162 full-text indexing and searching.
164 Since MySQL 5.5.5, the default storage engine is InnoDB_. This engine is fully
165 transactional and supports foreign key references. It's probably the best
166 choice at this point.
168 If you upgrade an existing project to MySQL 5.5.5 and subsequently add some
169 tables, ensure that your tables are using the same storage engine (i.e. MyISAM
170 vs. InnoDB). Specifically, if tables that have a ``ForeignKey`` between them
171 use different storage engines, you may see an error like the following when
174 _mysql_exceptions.OperationalError: (
175 1005, "Can't create table '\\db_name\\.#sql-4a8_ab' (errno: 150)"
178 .. versionchanged:: 1.4
180 In previous versions of Django, fixtures with forward references (i.e.
181 relations to rows that have not yet been inserted into the database) would fail
182 to load when using the InnoDB storage engine. This was due to the fact that InnoDB
183 deviates from the SQL standard by checking foreign key constraints immediately
184 instead of deferring the check until the transaction is committed. This
185 problem has been resolved in Django 1.4. Fixture data is now loaded with foreign key
186 checks turned off; foreign key checks are then re-enabled when the data has
187 finished loading, at which point the entire table is checked for invalid foreign
188 key references and an `IntegrityError` is raised if any are found.
190 .. _storage engines: http://dev.mysql.com/doc/refman/5.5/en/storage-engines.html
191 .. _MyISAM: http://dev.mysql.com/doc/refman/5.5/en/myisam-storage-engine.html
192 .. _InnoDB: http://dev.mysql.com/doc/refman/5.5/en/innodb.html
194 .. [#] Unless this was changed by the packager of your MySQL package. We've
195 had reports that the Windows Community Server installer sets up InnoDB as
196 the default storage engine, for example.
201 `MySQLdb`_ is the Python interface to MySQL. Version 1.2.1p2 or later is
202 required for full MySQL support in Django.
205 If you see ``ImportError: cannot import name ImmutableSet`` when trying to
206 use Django, your MySQLdb installation may contain an outdated ``sets.py``
207 file that conflicts with the built-in module of the same name from Python
208 2.4 and later. To fix this, verify that you have installed MySQLdb version
209 1.2.1p2 or newer, then delete the ``sets.py`` file in the MySQLdb
210 directory that was left by an earlier version.
212 .. _MySQLdb: http://sourceforge.net/projects/mysql-python
214 Creating your database
215 ----------------------
217 You can `create your database`_ using the command-line tools and this SQL::
219 CREATE DATABASE <dbname> CHARACTER SET utf8;
221 This ensures all tables and columns will use UTF-8 by default.
223 .. _create your database: http://dev.mysql.com/doc/refman/5.0/en/create-database.html
230 The collation setting for a column controls the order in which data is sorted
231 as well as what strings compare as equal. It can be set on a database-wide
232 level and also per-table and per-column. This is `documented thoroughly`_ in
233 the MySQL documentation. In all cases, you set the collation by directly
234 manipulating the database tables; Django doesn't provide a way to set this on
235 the model definition.
237 .. _documented thoroughly: http://dev.mysql.com/doc/refman/5.0/en/charset.html
239 By default, with a UTF-8 database, MySQL will use the
240 ``utf8_general_ci_swedish`` collation. This results in all string equality
241 comparisons being done in a *case-insensitive* manner. That is, ``"Fred"`` and
242 ``"freD"`` are considered equal at the database level. If you have a unique
243 constraint on a field, it would be illegal to try to insert both ``"aa"`` and
244 ``"AA"`` into the same column, since they compare as equal (and, hence,
245 non-unique) with the default collation.
247 In many cases, this default will not be a problem. However, if you really want
248 case-sensitive comparisons on a particular column or table, you would change
249 the column or table to use the ``utf8_bin`` collation. The main thing to be
250 aware of in this case is that if you are using MySQLdb 1.2.2, the database
251 backend in Django will then return bytestrings (instead of unicode strings) for
252 any character fields it receive from the database. This is a strong variation
253 from Django's normal practice of *always* returning unicode strings. It is up
254 to you, the developer, to handle the fact that you will receive bytestrings if
255 you configure your table(s) to use ``utf8_bin`` collation. Django itself should
256 mostly work smoothly with such columns (except for the ``contrib.sessions``
257 ``Session`` and ``contrib.admin`` ``LogEntry`` tables described below), but
258 your code must be prepared to call ``django.utils.encoding.smart_unicode()`` at
259 times if it really wants to work with consistent data -- Django will not do
260 this for you (the database backend layer and the model population layer are
261 separated internally so the database layer doesn't know it needs to make this
262 conversion in this one particular case).
264 If you're using MySQLdb 1.2.1p2, Django's standard
265 :class:`~django.db.models.CharField` class will return unicode strings even
266 with ``utf8_bin`` collation. However, :class:`~django.db.models.TextField`
267 fields will be returned as an ``array.array`` instance (from Python's standard
268 ``array`` module). There isn't a lot Django can do about that, since, again,
269 the information needed to make the necessary conversions isn't available when
270 the data is read in from the database. This problem was `fixed in MySQLdb
271 1.2.2`_, so if you want to use :class:`~django.db.models.TextField` with
272 ``utf8_bin`` collation, upgrading to version 1.2.2 and then dealing with the
273 bytestrings (which shouldn't be too difficult) as described above is the
274 recommended solution.
276 Should you decide to use ``utf8_bin`` collation for some of your tables with
277 MySQLdb 1.2.1p2 or 1.2.2, you should still use ``utf8_collation_ci_swedish``
278 (the default) collation for the :class:`django.contrib.sessions.models.Session`
279 table (usually called ``django_session``) and the
280 :class:`django.contrib.admin.models.LogEntry` table (usually called
281 ``django_admin_log``). Those are the two standard tables that use
282 :class:`~django.db.models.TextField` internally.
284 .. _fixed in MySQLdb 1.2.2: http://sourceforge.net/tracker/index.php?func=detail&aid=1495765&group_id=22307&atid=374932
286 Connecting to the database
287 --------------------------
289 Refer to the :doc:`settings documentation </ref/settings>`.
291 Connection settings are used in this order:
293 1. :setting:`OPTIONS`.
294 2. :setting:`NAME`, :setting:`USER`, :setting:`PASSWORD`,
295 :setting:`HOST`, :setting:`PORT`
296 3. MySQL option files.
298 In other words, if you set the name of the database in :setting:`OPTIONS`,
299 this will take precedence over :setting:`NAME`, which would override
300 anything in a `MySQL option file`_.
302 Here's a sample configuration which uses a MySQL option file::
307 'ENGINE': 'django.db.backends.mysql',
309 'read_default_file': '/path/to/my.cnf',
320 default-character-set = utf8
322 Several other MySQLdb connection options may be useful, such as ``ssl``,
323 ``use_unicode``, ``init_command``, and ``sql_mode``. Consult the
324 `MySQLdb documentation`_ for more details.
326 .. _MySQL option file: http://dev.mysql.com/doc/refman/5.0/en/option-files.html
327 .. _MySQLdb documentation: http://mysql-python.sourceforge.net/
332 When Django generates the schema, it doesn't specify a storage engine, so
333 tables will be created with whatever default storage engine your database
334 server is configured for. The easiest solution is to set your database server's
335 default storage engine to the desired engine.
337 If you're using a hosting service and can't change your server's default
338 storage engine, you have a couple of options.
340 * After the tables are created, execute an ``ALTER TABLE`` statement to
341 convert a table to a new storage engine (such as InnoDB)::
343 ALTER TABLE <tablename> ENGINE=INNODB;
345 This can be tedious if you have a lot of tables.
347 * Another option is to use the ``init_command`` option for MySQLdb prior to
348 creating your tables::
351 'init_command': 'SET storage_engine=INNODB',
354 This sets the default storage engine upon connecting to the database.
355 After your tables have been created, you should remove this option as it
356 adds a query that is only needed during table creation to each database
359 * Another method for changing the storage engine is described in
362 .. _AlterModelOnSyncDB: https://code.djangoproject.com/wiki/AlterModelOnSyncDB
367 There are `known issues`_ in even the latest versions of MySQL that can cause the
368 case of a table name to be altered when certain SQL statements are executed
369 under certain conditions. It is recommended that you use lowercase table
370 names, if possible, to avoid any problems that might arise from this behavior.
371 Django uses lowercase table names when it auto-generates table names from
372 models, so this is mainly a consideration if you are overriding the table name
373 via the :class:`~django.db.models.Options.db_table` parameter.
375 .. _known issues: http://bugs.mysql.com/bug.php?id=48875
380 Both the Django ORM and MySQL (when using the InnoDB :ref:`storage engine
381 <mysql-storage-engines>`) support database :ref:`savepoints
382 <topics-db-transactions-savepoints>`, but this feature wasn't available in
383 Django until version 1.4 when such supports was added.
385 If you use the MyISAM storage engine please be aware of the fact that you will
386 receive database-generated errors if you try to use the :ref:`savepoint-related
387 methods of the transactions API <topics-db-transactions-savepoints>`. The reason
388 for this is that detecting the storage engine of a MySQL database/table is an
389 expensive operation so it was decided it isn't worth to dynamically convert
390 these methods in no-op's based in the results of such detection.
392 Notes on specific fields
393 ------------------------
398 .. versionchanged:: 1.2
400 In previous versions of Django when running under MySQL ``BooleanFields`` would
401 return their data as ``ints``, instead of true ``bools``. See the release
402 notes for a complete description of the change.
407 Any fields that are stored with ``VARCHAR`` column types have their
408 ``max_length`` restricted to 255 characters if you are using ``unique=True``
409 for the field. This affects :class:`~django.db.models.CharField`,
410 :class:`~django.db.models.SlugField` and
411 :class:`~django.db.models.CommaSeparatedIntegerField`.
413 Furthermore, if you are using a version of MySQL prior to 5.0.3, all of those
414 column types have a maximum length restriction of 255 characters, regardless
415 of whether ``unique=True`` is specified or not.
420 MySQL does not have a timezone-aware column type. If an attempt is made to
421 store a timezone-aware ``time`` or ``datetime`` to a
422 :class:`~django.db.models.TimeField` or :class:`~django.db.models.DateTimeField`
423 respectively, a ``ValueError`` is raised rather than truncating data.
425 MySQL does not store fractions of seconds. Fractions of seconds are truncated
426 to zero when the time is stored.
428 Row locking with ``QuerySet.select_for_update()``
429 -------------------------------------------------
431 MySQL does not support the ``NOWAIT`` option to the ``SELECT ... FOR UPDATE``
432 statement. If ``select_for_update()`` is used with ``nowait=True`` then a
433 ``DatabaseError`` will be raised.
440 SQLite_ provides an excellent development alternative for applications that
441 are predominantly read-only or require a smaller installation footprint. As
442 with all database servers, though, there are some differences that are
443 specific to SQLite that you should be aware of.
445 .. _SQLite: http://www.sqlite.org/
447 .. _sqlite-string-matching:
449 Substring matching and case sensitivity
450 -----------------------------------------
452 For all SQLite versions, there is some slightly counter-intuitive behavior when
453 attempting to match some types of strings. These are triggered when using the
454 :lookup:`iexact` or :lookup:`contains` filters in Querysets. The behavior
455 splits into two cases:
457 1. For substring matching, all matches are done case-insensitively. That is a
458 filter such as ``filter(name__contains="aa")`` will match a name of ``"Aabb"``.
460 2. For strings containing characters outside the ASCII range, all exact string
461 matches are performed case-sensitively, even when the case-insensitive options
462 are passed into the query. So the :lookup:`iexact` filter will behave exactly
463 the same as the :lookup:`exact` filter in these cases.
465 Some possible workarounds for this are `documented at sqlite.org`_, but they
466 aren't utilised by the default SQLite backend in Django, as incorporating them
467 would be fairly difficult to do robustly. Thus, Django exposes the default
468 SQLite behavior and you should be aware of this when doing case-insensitive or
471 .. _documented at sqlite.org: http://www.sqlite.org/faq.html#q18
473 SQLite 3.3.6 or newer strongly recommended
474 ------------------------------------------
476 Versions of SQLite 3.3.5 and older contains the following bugs:
478 * A bug when `handling`_ ``ORDER BY`` parameters. This can cause problems when
479 you use the ``select`` parameter for the ``extra()`` QuerySet method. The bug
480 can be identified by the error message ``OperationalError: ORDER BY terms
481 must not be non-integer constants``.
483 * A bug when handling `aggregation`_ together with DateFields and
486 .. _handling: http://www.sqlite.org/cvstrac/tktview?tn=1768
487 .. _aggregation: https://code.djangoproject.com/ticket/10031
489 SQLite 3.3.6 was released in April 2006, so most current binary distributions
490 for different platforms include newer version of SQLite usable from Python
491 through either the ``pysqlite2`` or the ``sqlite3`` modules.
493 However, some platform/Python version combinations include older versions of
494 SQLite (e.g. the official binary distribution of Python 2.5 for Windows, 2.5.4
495 as of this writing, includes SQLite 3.3.4). There are (as of Django 1.1) even
496 some tests in the Django test suite that will fail when run under this setup.
498 As described :ref:`below<using-newer-versions-of-pysqlite>`, this can be solved
499 by downloading and installing a newer version of ``pysqlite2``
500 (``pysqlite-2.x.x.win32-py2.5.exe`` in the described case) that includes and
501 uses a newer version of SQLite. Python 2.6 for Windows ships with a version of
502 SQLite that is not affected by these issues.
507 The Ubuntu "Intrepid Ibex" (8.10) SQLite 3.5.9-3 package contains a bug that
508 causes problems with the evaluation of query expressions. If you are using
509 Ubuntu "Intrepid Ibex", you will need to update the package to version
510 3.5.9-3ubuntu1 or newer (recommended) or find an alternate source for SQLite
511 packages, or install SQLite from source.
513 At one time, Debian Lenny shipped with the same malfunctioning SQLite 3.5.9-3
514 package. However the Debian project has subsequently issued updated versions
515 of the SQLite package that correct these bugs. If you find you are getting
516 unexpected results under Debian, ensure you have updated your SQLite package
519 The problem does not appear to exist with other versions of SQLite packaged
520 with other operating systems.
525 SQLite version 3.6.2 (released August 30, 2008) introduced a bug into ``SELECT
526 DISTINCT`` handling that is triggered by, amongst other things, Django's
527 ``DateQuerySet`` (returned by the ``dates()`` method on a queryset).
529 You should avoid using this version of SQLite with Django. Either upgrade to
530 3.6.3 (released September 22, 2008) or later, or downgrade to an earlier
533 .. _using-newer-versions-of-pysqlite:
535 Using newer versions of the SQLite DB-API 2.0 driver
536 ----------------------------------------------------
538 For versions of Python 2.5 or newer that include ``sqlite3`` in the standard
539 library Django will now use a ``pysqlite2`` interface in preference to
540 ``sqlite3`` if it finds one is available.
542 This provides the ability to upgrade both the DB-API 2.0 interface or SQLite 3
543 itself to versions newer than the ones included with your particular Python
544 binary distribution, if needed.
546 "Database is locked" errors
547 ---------------------------
549 SQLite is meant to be a lightweight database, and thus can't support a high
550 level of concurrency. ``OperationalError: database is locked`` errors indicate
551 that your application is experiencing more concurrency than ``sqlite`` can
552 handle in default configuration. This error means that one thread or process has
553 an exclusive lock on the database connection and another thread timed out
554 waiting for the lock the be released.
556 Python's SQLite wrapper has
557 a default timeout value that determines how long the second thread is allowed to
558 wait on the lock before it times out and raises the ``OperationalError: database
561 If you're getting this error, you can solve it by:
563 * Switching to another database backend. At a certain point SQLite becomes
564 too "lite" for real-world applications, and these sorts of concurrency
565 errors indicate you've reached that point.
567 * Rewriting your code to reduce concurrency and ensure that database
568 transactions are short-lived.
570 * Increase the default timeout value by setting the ``timeout`` database
579 This will simply make SQLite wait a bit longer before throwing "database
580 is locked" errors; it won't really do anything to solve them.
582 ``QuerySet.select_for_update()`` not supported
583 ----------------------------------------------
585 SQLite does not support the ``SELECT ... FOR UPDATE`` syntax. Calling it will
588 .. _sqlite-connection-queries:
590 Parameters not quoted in ``connection.queries``
591 -----------------------------------------------
593 ``sqlite3`` does not provide a way to retrieve the SQL after quoting and
594 substituting the parameters. Instead, the SQL in ``connection.queries`` is
595 rebuilt with a simple string interpolation. It may be incorrect. Make sure
596 you add quotes where necessary before copying a query into a SQLite shell.
603 Django supports `Oracle Database Server`_ versions 9i and
604 higher. Oracle version 10g or later is required to use Django's
605 ``regex`` and ``iregex`` query operators. You will also need at least
606 version 4.3.1 of the `cx_Oracle`_ Python driver.
608 Note that due to a Unicode-corruption bug in ``cx_Oracle`` 5.0, that
609 version of the driver should **not** be used with Django;
610 ``cx_Oracle`` 5.0.1 resolved this issue, so if you'd like to use a
611 more recent ``cx_Oracle``, use version 5.0.1.
613 ``cx_Oracle`` 5.0.1 or greater can optionally be compiled with the
614 ``WITH_UNICODE`` environment variable. This is recommended but not
617 .. _`Oracle Database Server`: http://www.oracle.com/
618 .. _`cx_Oracle`: http://cx-oracle.sourceforge.net/
620 In order for the ``python manage.py syncdb`` command to work, your Oracle
621 database user must have privileges to run the following commands:
628 To run Django's test suite, the user needs these *additional* privileges:
634 * CONNECT WITH ADMIN OPTION
635 * RESOURCE WITH ADMIN OPTION
637 Connecting to the database
638 --------------------------
640 Your Django settings.py file should look something like this for Oracle::
644 'ENGINE': 'django.db.backends.oracle',
647 'PASSWORD': 'a_password',
654 If you don't use a ``tnsnames.ora`` file or a similar naming method that
655 recognizes the SID ("xe" in this example), then fill in both
656 :setting:`HOST` and :setting:`PORT` like so::
660 'ENGINE': 'django.db.backends.oracle',
663 'PASSWORD': 'a_password',
664 'HOST': 'dbprod01ned.mycompany.com',
669 You should supply both :setting:`HOST` and :setting:`PORT`, or leave both
675 If you plan to run Django in a multithreaded environment (e.g. Apache in Windows
676 using the default MPM module), then you **must** set the ``threaded`` option of
677 your Oracle database configuration to True::
683 Failure to do this may result in crashes and other odd behavior.
685 INSERT ... RETURNING INTO
686 -------------------------
688 By default, the Oracle backend uses a ``RETURNING INTO`` clause to efficiently
689 retrieve the value of an ``AutoField`` when inserting new rows. This behavior
690 may result in a ``DatabaseError`` in certain unusual setups, such as when
691 inserting into a remote table, or into a view with an ``INSTEAD OF`` trigger.
692 The ``RETURNING INTO`` clause can be disabled by setting the
693 ``use_returning_into`` option of the database configuration to False::
696 'use_returning_into': False,
699 In this case, the Oracle backend will use a separate ``SELECT`` query to
700 retrieve AutoField values.
705 Oracle imposes a name length limit of 30 characters. To accommodate this, the
706 backend truncates database identifiers to fit, replacing the final four
707 characters of the truncated name with a repeatable MD5 hash value.
709 When running syncdb, an ``ORA-06552`` error may be encountered if
710 certain Oracle keywords are used as the name of a model field or the
711 value of a ``db_column`` option. Django quotes all identifiers used
712 in queries to prevent most such problems, but this error can still
713 occur when an Oracle datatype is used as a column name. In
714 particular, take care to avoid using the names ``date``,
715 ``timestamp``, ``number`` or ``float`` as a field name.
717 NULL and empty strings
718 ----------------------
720 Django generally prefers to use the empty string ('') rather than
721 NULL, but Oracle treats both identically. To get around this, the
722 Oracle backend coerces the ``null=True`` option on fields that have
723 the empty string as a possible value. When fetching from the database,
724 it is assumed that a NULL value in one of these fields really means
725 the empty string, and the data is silently converted to reflect this
728 ``TextField`` limitations
729 -------------------------
731 The Oracle backend stores ``TextFields`` as ``NCLOB`` columns. Oracle imposes
732 some limitations on the usage of such LOB columns in general:
734 * LOB columns may not be used as primary keys.
736 * LOB columns may not be used in indexes.
738 * LOB columns may not be used in a ``SELECT DISTINCT`` list. This means that
739 attempting to use the ``QuerySet.distinct`` method on a model that
740 includes ``TextField`` columns will result in an error when run against
741 Oracle. As a workaround, use the ``QuerySet.defer`` method in conjunction
742 with ``distinct()`` to prevent ``TextField`` columns from being included in
743 the ``SELECT DISTINCT`` list.
745 .. _third-party-notes:
747 Using a 3rd-party database backend
748 ==================================
750 In addition to the officially supported databases, there are backends provided
751 by 3rd parties that allow you to use other databases with Django:
753 * `Sybase SQL Anywhere`_
755 * `Microsoft SQL Server 2005`_
760 The Django versions and ORM features supported by these unofficial backends
761 vary considerably. Queries regarding the specific capabilities of these
762 unofficial backends, along with any support queries, should be directed to
763 the support channels provided by each 3rd party project.
765 .. _Sybase SQL Anywhere: http://code.google.com/p/sqlany-django/
766 .. _IBM DB2: http://code.google.com/p/ibm-db/
767 .. _Microsoft SQL Server 2005: http://code.google.com/p/django-mssql/
768 .. _Firebird: http://code.google.com/p/django-firebird/
769 .. _ODBC: http://code.google.com/p/django-pyodbc/
770 .. _ADSDB: http://code.google.com/p/adsdb-django/