Sophie

Sophie

distrib > Arklinux > devel > i586 > media > main > by-pkgid > 5fcb1fedf34660bc240dc59b7bfcebc4 > files > 373

django-doc-1.2.3-1ark.noarch.rpm


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Databases &mdash; Django v1.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="Django v1.2 documentation" href="../index.html" />
    <link rel="up" title="API Reference" href="index.html" />
    <link rel="next" title="django-admin.py and manage.py" href="django-admin.html" />
    <link rel="prev" title="django.contrib.webdesign" href="contrib/webdesign.html" />
 
<script type="text/javascript" src="../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>

  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django v1.2 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="contrib/webdesign.html" title="django.contrib.webdesign">previous</a> 
     |
    <a href="index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="django-admin.html" title="django-admin.py and manage.py">next</a> &raquo;</div>
    </div>
    
    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-databases">
            
  <div class="section" id="s-databases">
<span id="databases"></span><h1>Databases<a class="headerlink" href="#databases" title="Permalink to this headline">¶</a></h1>
<p>Django attempts to support as many features as possible on all database
backends. However, not all database backends are alike, and we&#8217;ve had to make
design decisions on which features to support and which assumptions we can make
safely.</p>
<p>This file describes some of the features that might be relevant to Django
usage. Of course, it is not intended as a replacement for server-specific
documentation or reference manuals.</p>
<div class="section" id="s-postgresql-notes">
<span id="s-id1"></span><span id="postgresql-notes"></span><span id="id1"></span><h2>PostgreSQL notes<a class="headerlink" href="#postgresql-notes" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-postgresql-8-2-to-8-2-4">
<span id="postgresql-8-2-to-8-2-4"></span><h3>PostgreSQL 8.2 to 8.2.4<a class="headerlink" href="#postgresql-8-2-to-8-2-4" title="Permalink to this headline">¶</a></h3>
<p>The implementation of the population statistics aggregates <tt class="docutils literal"><span class="pre">STDDEV_POP</span></tt> and
<tt class="docutils literal"><span class="pre">VAR_POP</span></tt> that shipped with PostgreSQL 8.2 to 8.2.4 are <a class="reference external" href="http://archives.postgresql.org/pgsql-bugs/2007-07/msg00046.php">known to be
faulty</a>. Users of these releases of PostgreSQL are advised to upgrade to
<a class="reference external" href="http://developer.postgresql.org/pgdocs/postgres/release-8-2-5.html">Release 8.2.5</a> or later. Django will raise a <tt class="docutils literal"><span class="pre">NotImplementedError</span></tt> if you
attempt to use the <tt class="docutils literal"><span class="pre">StdDev(sample=False)</span></tt> or <tt class="docutils literal"><span class="pre">Variance(sample=False)</span></tt>
aggregate with a database backend that falls within the affected release range.</p>
</div>
<div class="section" id="s-transaction-handling">
<span id="transaction-handling"></span><h3>Transaction handling<a class="headerlink" href="#transaction-handling" title="Permalink to this headline">¶</a></h3>
<p><a class="reference internal" href="../topics/db/transactions.html"><em>By default</em></a>, Django starts a transaction when a
database connection is first used and commits the result at the end of the
request/response handling. The PostgreSQL backends normally operate the same
as any other Django backend in this respect.</p>
<div class="section" id="s-autocommit-mode">
<span id="autocommit-mode"></span><h4>Autocommit mode<a class="headerlink" href="#autocommit-mode" title="Permalink to this headline">¶</a></h4>
<div class="versionadded">
<span class="title">New in Django 1.1:</span> <a class="reference internal" href="../releases/1.1.html"><em>Please, see the release notes</em></a></div>
<p>If your application is particularly read-heavy and doesn&#8217;t make many
database writes, the overhead of a constantly open transaction can
sometimes be noticeable. For those situations, if you&#8217;re using the
<tt class="docutils literal"><span class="pre">postgresql_psycopg2</span></tt> backend, you can configure Django to use
<em>&#8220;autocommit&#8221;</em> behavior for the connection, meaning that each database
operation will normally be in its own transaction, rather than having
the transaction extend over multiple operations. In this case, you can
still manually start a transaction if you&#8217;re doing something that
requires consistency across multiple database operations. The
autocommit behavior is enabled by setting the <tt class="docutils literal"><span class="pre">autocommit</span></tt> key in
the <a class="reference internal" href="settings.html#std:setting-OPTIONS"><tt class="xref std std-setting docutils literal"><span class="pre">OPTIONS</span></tt></a> part of your database configuration in
<a class="reference internal" href="settings.html#std:setting-DATABASES"><tt class="xref std std-setting docutils literal"><span class="pre">DATABASES</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">OPTIONS</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&quot;autocommit&quot;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p>In this configuration, Django still ensures that <a class="reference internal" href="../topics/db/queries.html#topics-db-queries-delete"><em>delete()</em></a> and <a class="reference internal" href="../topics/db/queries.html#topics-db-queries-update"><em>update()</em></a>
queries run inside a single transaction, so that either all the affected
objects are changed or none of them are.</p>
<div class="admonition-this-is-database-level-autocommit admonition ">
<p class="first admonition-title">This is database-level autocommit</p>
<p class="last">This functionality is not the same as the
<a class="reference internal" href="../topics/db/transactions.html#topics-db-transactions-autocommit"><em>django.db.transaction.autocommit</em></a> decorator. That decorator
is a Django-level implementation that commits automatically after
data changing operations. The feature enabled using the
<a class="reference internal" href="settings.html#std:setting-OPTIONS"><tt class="xref std std-setting docutils literal"><span class="pre">OPTIONS</span></tt></a> option provides autocommit behavior at the
database adapter level. It commits after <em>every</em> operation.</p>
</div>
<p>If you are using this feature and performing an operation akin to delete or
updating that requires multiple operations, you are strongly recommended to
wrap you operations in manual transaction handling to ensure data consistency.
You should also audit your existing code for any instances of this behavior
before enabling this feature. It's faster, but it provides less automatic
protection for multi-call operations.</p>
</div>
<div class="section" id="s-indexes-for-varchar-and-text-columns">
<span id="indexes-for-varchar-and-text-columns"></span><h4>Indexes for <tt class="docutils literal"><span class="pre">varchar</span></tt> and <tt class="docutils literal"><span class="pre">text</span></tt> columns<a class="headerlink" href="#indexes-for-varchar-and-text-columns" title="Permalink to this headline">¶</a></h4>
<div class="versionadded">
<span class="title">New in Django 1.1.2:</span> <a class="reference internal" href="../releases/1.1.2.html"><em>Please, see the release notes</em></a></div>
<p>When specifying <tt class="docutils literal"><span class="pre">db_index=True</span></tt> on your model fields, Django typically
outputs a single <tt class="docutils literal"><span class="pre">CREATE</span> <span class="pre">INDEX</span></tt> statement.  However, if the database type
for the field is either <tt class="docutils literal"><span class="pre">varchar</span></tt> or <tt class="docutils literal"><span class="pre">text</span></tt> (e.g., used by <tt class="docutils literal"><span class="pre">CharField</span></tt>,
<tt class="docutils literal"><span class="pre">FileField</span></tt>, and <tt class="docutils literal"><span class="pre">TextField</span></tt>), then Django will create
an additional index that uses an appropriate <a class="reference external" href="http://www.postgresql.org/docs/8.4/static/indexes-opclass.html">PostgreSQL operator class</a>
for the column.  The extra index is necessary to correctly perfrom
lookups that use the <tt class="docutils literal"><span class="pre">LIKE</span></tt> operator in their SQL, as is done with the
<tt class="docutils literal"><span class="pre">contains</span></tt> and <tt class="docutils literal"><span class="pre">startswith</span></tt> lookup types.</p>
</div>
</div>
</div>
<div class="section" id="s-mysql-notes">
<span id="s-id2"></span><span id="mysql-notes"></span><span id="id2"></span><h2>MySQL notes<a class="headerlink" href="#mysql-notes" title="Permalink to this headline">¶</a></h2>
<p>Django expects the database to support transactions, referential integrity, and
Unicode (UTF-8 encoding). Fortunately, <a class="reference external" href="http://www.mysql.com/">MySQL</a> has all these features as
available as far back as 3.23. While it may be possible to use 3.23 or 4.0,
you'll probably have less trouble if you use 4.1 or 5.0.</p>
<div class="section" id="s-mysql-4-1">
<span id="mysql-4-1"></span><h3>MySQL 4.1<a class="headerlink" href="#mysql-4-1" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://dev.mysql.com/doc/refman/4.1/en/index.html">MySQL 4.1</a> has greatly improved support for character sets. It is possible to
set different default character sets on the database, table, and column.
Previous versions have only a server-wide character set setting. It's also the
first version where the character set can be changed on the fly. 4.1 also has
support for views, but Django currently doesn't use views.</p>
</div>
<div class="section" id="s-mysql-5-0">
<span id="mysql-5-0"></span><h3>MySQL 5.0<a class="headerlink" href="#mysql-5-0" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://dev.mysql.com/doc/refman/5.0/en/index.html">MySQL 5.0</a> adds the <tt class="docutils literal"><span class="pre">information_schema</span></tt> database, which contains detailed
data on all database schema. Django's <tt class="docutils literal"><span class="pre">inspectdb</span></tt> feature uses this
<tt class="docutils literal"><span class="pre">information_schema</span></tt> if it's available. 5.0 also has support for stored
procedures, but Django currently doesn't use stored procedures.</p>
</div>
<div class="section" id="s-storage-engines">
<span id="storage-engines"></span><h3>Storage engines<a class="headerlink" href="#storage-engines" title="Permalink to this headline">¶</a></h3>
<p>MySQL has several <a class="reference external" href="http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html">storage engines</a> (previously called table types). You can
change the default storage engine in the server configuration.</p>
<p>The default engine is <a class="reference external" href="http://dev.mysql.com/doc/refman/5.0/en/myisam-storage-engine.html">MyISAM</a> <a class="footnote-reference" href="#id7" id="id5">[1]</a>. The main drawback of MyISAM is that it
doesn't currently support transactions or foreign keys. On the plus side, it's
currently the only engine that supports full-text indexing and searching.</p>
<p>The <a class="reference external" href="http://dev.mysql.com/doc/refman/5.0/en/innodb.html">InnoDB</a> engine is fully transactional and supports foreign key references.</p>
<p>The <a class="reference external" href="http://dev.mysql.com/doc/refman/5.0/en/bdb-storage-engine.html">BDB</a> engine, like InnoDB, is also fully transactional and supports foreign
key references. However, its use seems to be deprecated.</p>
<p><a class="reference external" href="http://dev.mysql.com/doc/refman/5.1/en/storage-engines-other.html">Other storage engines</a>, including <a class="reference external" href="http://forge.mysql.com/projects/project.php?id=139">SolidDB</a> and <a class="reference external" href="http://dev.mysql.com/doc/falcon/en/index.html">Falcon</a>, are on the horizon.
For now, InnoDB is probably your best choice.</p>
<table class="docutils footnote" frame="void" id="id7" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id5">[1]</a></td><td>Unless this was changed by the packager of your MySQL package. We've
had reports that the Windows Community Server installer sets up InnoDB as
the default storage engine, for example.</td></tr>
</tbody>
</table>
</div>
<div class="section" id="s-mysqldb">
<span id="mysqldb"></span><h3>MySQLdb<a class="headerlink" href="#mysqldb" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://sourceforge.net/projects/mysql-python">MySQLdb</a> is the Python interface to MySQL. Version 1.2.1p2 or later is
required for full MySQL support in Django.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you see <tt class="docutils literal"><span class="pre">ImportError:</span> <span class="pre">cannot</span> <span class="pre">import</span> <span class="pre">name</span> <span class="pre">ImmutableSet</span></tt> when trying to
use Django, your MySQLdb installation may contain an outdated <tt class="docutils literal"><span class="pre">sets.py</span></tt>
file that conflicts with the built-in module of the same name from Python
2.4 and later. To fix this, verify that you have installed MySQLdb version
1.2.1p2 or newer, then delete the <tt class="docutils literal"><span class="pre">sets.py</span></tt> file in the MySQLdb
directory that was left by an earlier version.</p>
</div>
</div>
<div class="section" id="s-creating-your-database">
<span id="creating-your-database"></span><h3>Creating your database<a class="headerlink" href="#creating-your-database" title="Permalink to this headline">¶</a></h3>
<p>You can <a class="reference external" href="http://dev.mysql.com/doc/refman/5.0/en/create-database.html">create your database</a> using the command-line tools and this SQL:</p>
<div class="highlight-python"><pre>CREATE DATABASE &lt;dbname&gt; CHARACTER SET utf8;</pre>
</div>
<p>This ensures all tables and columns will use UTF-8 by default.</p>
<div class="section" id="s-collation-settings">
<span id="s-mysql-collation"></span><span id="collation-settings"></span><span id="mysql-collation"></span><h4>Collation settings<a class="headerlink" href="#collation-settings" title="Permalink to this headline">¶</a></h4>
<p>The collation setting for a column controls the order in which data is sorted
as well as what strings compare as equal. It can be set on a database-wide
level and also per-table and per-column. This is <a class="reference external" href="http://dev.mysql.com/doc/refman/5.0/en/charset.html">documented thoroughly</a> in
the MySQL documentation. In all cases, you set the collation by directly
manipulating the database tables; Django doesn't provide a way to set this on
the model definition.</p>
<p>By default, with a UTF-8 database, MySQL will use the
<tt class="docutils literal"><span class="pre">utf8_general_ci_swedish</span></tt> collation. This results in all string equality
comparisons being done in a <em>case-insensitive</em> manner. That is, <tt class="docutils literal"><span class="pre">&quot;Fred&quot;</span></tt> and
<tt class="docutils literal"><span class="pre">&quot;freD&quot;</span></tt> are considered equal at the database level. If you have a unique
constraint on a field, it would be illegal to try to insert both <tt class="docutils literal"><span class="pre">&quot;aa&quot;</span></tt> and
<tt class="docutils literal"><span class="pre">&quot;AA&quot;</span></tt> into the same column, since they compare as equal (and, hence,
non-unique) with the default collation.</p>
<p>In many cases, this default will not be a problem. However, if you really want
case-sensitive comparisons on a particular column or table, you would change
the column or table to use the <tt class="docutils literal"><span class="pre">utf8_bin</span></tt> collation. The main thing to be
aware of in this case is that if you are using MySQLdb 1.2.2, the database backend in Django will then return
bytestrings (instead of unicode strings) for any character fields it returns
receive from the database. This is a strong variation from Django's normal
practice of <em>always</em> returning unicode strings. It is up to you, the
developer, to handle the fact that you will receive bytestrings if you
configure your table(s) to use <tt class="docutils literal"><span class="pre">utf8_bin</span></tt> collation. Django itself should work
smoothly with such columns, but if your code must be prepared to call
<tt class="docutils literal"><span class="pre">django.utils.encoding.smart_unicode()</span></tt> at times if it really wants to work
with consistent data -- Django will not do this for you (the database backend
layer and the model population layer are separated internally so the database
layer doesn't know it needs to make this conversion in this one particular
case).</p>
<p>If you're using MySQLdb 1.2.1p2, Django's standard
<a class="reference internal" href="models/fields.html#django.db.models.CharField" title="django.db.models.CharField"><tt class="xref py py-class docutils literal"><span class="pre">CharField</span></tt></a> class will return unicode strings even
with <tt class="docutils literal"><span class="pre">utf8_bin</span></tt> collation. However, <a class="reference internal" href="models/fields.html#django.db.models.TextField" title="django.db.models.TextField"><tt class="xref py py-class docutils literal"><span class="pre">TextField</span></tt></a>
fields will be returned as an <tt class="docutils literal"><span class="pre">array.array</span></tt> instance (from Python's standard
<tt class="docutils literal"><span class="pre">array</span></tt> module). There isn't a lot Django can do about that, since, again,
the information needed to make the necessary conversions isn't available when
the data is read in from the database. This problem was <a class="reference external" href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1495765&amp;group_id=22307&amp;atid=374932">fixed in MySQLdb
1.2.2</a>, so if you want to use <a class="reference internal" href="models/fields.html#django.db.models.TextField" title="django.db.models.TextField"><tt class="xref py py-class docutils literal"><span class="pre">TextField</span></tt></a> with
<tt class="docutils literal"><span class="pre">utf8_bin</span></tt> collation, upgrading to version 1.2.2 and then dealing with the
bytestrings (which shouldn't be too difficult) is the recommended solution.</p>
<p>Should you decide to use <tt class="docutils literal"><span class="pre">utf8_bin</span></tt> collation for some of your tables with
MySQLdb 1.2.1p2, you should still use <tt class="docutils literal"><span class="pre">utf8_collation_ci_swedish</span></tt> (the
default) collation for the <tt class="xref py py-class docutils literal"><span class="pre">django.contrib.sessions.models.Session</span></tt>
table (usually called <tt class="docutils literal"><span class="pre">django_session</span></tt>) and the
<tt class="xref py py-class docutils literal"><span class="pre">django.contrib.admin.models.LogEntry</span></tt> table (usually called
<tt class="docutils literal"><span class="pre">django_admin_log</span></tt>). Those are the two standard tables that use
<tt class="xref py py-class docutils literal"><span class="pre">TextField</span></tt> internally.</p>
</div>
</div>
<div class="section" id="s-connecting-to-the-database">
<span id="connecting-to-the-database"></span><h3>Connecting to the database<a class="headerlink" href="#connecting-to-the-database" title="Permalink to this headline">¶</a></h3>
<p>Refer to the <a class="reference internal" href="settings.html"><em>settings documentation</em></a>.</p>
<p>Connection settings are used in this order:</p>
<ol class="arabic simple">
<li><a class="reference internal" href="settings.html#std:setting-OPTIONS"><tt class="xref std std-setting docutils literal"><span class="pre">OPTIONS</span></tt></a>.</li>
<li><a class="reference internal" href="settings.html#std:setting-NAME"><tt class="xref std std-setting docutils literal"><span class="pre">NAME</span></tt></a>, <a class="reference internal" href="settings.html#std:setting-USER"><tt class="xref std std-setting docutils literal"><span class="pre">USER</span></tt></a>, <a class="reference internal" href="settings.html#std:setting-PASSWORD"><tt class="xref std std-setting docutils literal"><span class="pre">PASSWORD</span></tt></a>,
<a class="reference internal" href="settings.html#std:setting-HOST"><tt class="xref std std-setting docutils literal"><span class="pre">HOST</span></tt></a>, <a class="reference internal" href="settings.html#std:setting-PORT"><tt class="xref std std-setting docutils literal"><span class="pre">PORT</span></tt></a></li>
<li>MySQL option files.</li>
</ol>
<p>In other words, if you set the name of the database in <tt class="docutils literal"><span class="pre">OPTIONS</span></tt>,
this will take precedence over <tt class="docutils literal"><span class="pre">NAME</span></tt>, which would override
anything in a <a class="reference external" href="http://dev.mysql.com/doc/refman/5.0/en/option-files.html">MySQL option file</a>.</p>
<p>Here's a sample configuration which uses a MySQL option file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># settings.py</span>
<span class="n">DATABASES</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;default&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s">&#39;ENGINE&#39;</span><span class="p">:</span> <span class="s">&#39;django.db.backends.mysql&#39;</span><span class="p">,</span>
        <span class="s">&#39;OPTIONS&#39;</span><span class="p">:</span> <span class="p">{</span>
            <span class="s">&#39;read_default_file&#39;</span><span class="p">:</span> <span class="s">&#39;/path/to/my.cnf&#39;</span><span class="p">,</span>
        <span class="p">},</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="c"># my.cnf</span>
<span class="p">[</span><span class="n">client</span><span class="p">]</span>
<span class="n">database</span> <span class="o">=</span> <span class="n">NAME</span>
<span class="n">user</span> <span class="o">=</span> <span class="n">USER</span>
<span class="n">password</span> <span class="o">=</span> <span class="n">PASSWORD</span>
<span class="n">default</span><span class="o">-</span><span class="n">character</span><span class="o">-</span><span class="nb">set</span> <span class="o">=</span> <span class="n">utf8</span>
</pre></div>
</div>
<p>Several other MySQLdb connection options may be useful, such as <tt class="docutils literal"><span class="pre">ssl</span></tt>,
<tt class="docutils literal"><span class="pre">use_unicode</span></tt>, <tt class="docutils literal"><span class="pre">init_command</span></tt>, and <tt class="docutils literal"><span class="pre">sql_mode</span></tt>. Consult the
<a class="reference external" href="http://mysql-python.sourceforge.net/">MySQLdb documentation</a> for more details.</p>
</div>
<div class="section" id="s-creating-your-tables">
<span id="creating-your-tables"></span><h3>Creating your tables<a class="headerlink" href="#creating-your-tables" title="Permalink to this headline">¶</a></h3>
<p>When Django generates the schema, it doesn't specify a storage engine, so
tables will be created with whatever default storage engine your database
server is configured for. The easiest solution is to set your database server's
default storage engine to the desired engine.</p>
<p>If you're using a hosting service and can't change your server's default
storage engine, you have a couple of options.</p>
<ul>
<li><p class="first">After the tables are created, execute an <tt class="docutils literal"><span class="pre">ALTER</span> <span class="pre">TABLE</span></tt> statement to
convert a table to a new storage engine (such as InnoDB):</p>
<div class="highlight-python"><pre>ALTER TABLE &lt;tablename&gt; ENGINE=INNODB;</pre>
</div>
<p>This can be tedious if you have a lot of tables.</p>
</li>
<li><p class="first">Another option is to use the <tt class="docutils literal"><span class="pre">init_command</span></tt> option for MySQLdb prior to
creating your tables:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">OPTIONS</span> <span class="o">=</span> <span class="p">{</span>
   <span class="s">&quot;init_command&quot;</span><span class="p">:</span> <span class="s">&quot;SET storage_engine=INNODB&quot;</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p>This sets the default storage engine upon connecting to the database.
After your tables have been created, you should remove this option.</p>
</li>
<li><p class="first">Another method for changing the storage engine is described in
<a class="reference external" href="http://code.djangoproject.com/wiki/AlterModelOnSyncDB">AlterModelOnSyncDB</a>.</p>
</li>
</ul>
</div>
<div class="section" id="s-notes-on-specific-fields">
<span id="notes-on-specific-fields"></span><h3>Notes on specific fields<a class="headerlink" href="#notes-on-specific-fields" title="Permalink to this headline">¶</a></h3>
<div class="section" id="s-boolean-fields">
<span id="boolean-fields"></span><h4>Boolean fields<a class="headerlink" href="#boolean-fields" title="Permalink to this headline">¶</a></h4>
<div class="versionchanged">
<span class="title">Changed in Django 1.2:</span> <a class="reference internal" href="../releases/1.2.html"><em>Please, see the release notes</em></a></div>
<p>In previous versions of Django when running under MySQL <tt class="docutils literal"><span class="pre">BooleanFields</span></tt> would
return their data as <tt class="docutils literal"><span class="pre">ints</span></tt>, instead of true <tt class="docutils literal"><span class="pre">bools</span></tt>.  See the release
notes for a complete description of the change.</p>
</div>
<div class="section" id="s-character-fields">
<span id="character-fields"></span><h4>Character fields<a class="headerlink" href="#character-fields" title="Permalink to this headline">¶</a></h4>
<p>Any fields that are stored with <tt class="docutils literal"><span class="pre">VARCHAR</span></tt> column types have their
<tt class="docutils literal"><span class="pre">max_length</span></tt> restricted to 255 characters if you are using <tt class="docutils literal"><span class="pre">unique=True</span></tt>
for the field. This affects <a class="reference internal" href="models/fields.html#django.db.models.CharField" title="django.db.models.CharField"><tt class="xref py py-class docutils literal"><span class="pre">CharField</span></tt></a>,
<a class="reference internal" href="models/fields.html#django.db.models.SlugField" title="django.db.models.SlugField"><tt class="xref py py-class docutils literal"><span class="pre">SlugField</span></tt></a> and
<a class="reference internal" href="models/fields.html#django.db.models.CommaSeparatedIntegerField" title="django.db.models.CommaSeparatedIntegerField"><tt class="xref py py-class docutils literal"><span class="pre">CommaSeparatedIntegerField</span></tt></a>.</p>
<p>Furthermore, if you are using a version of MySQL prior to 5.0.3, all of those
column types have a maximum length restriction of 255 characters, regardless
of whether <tt class="docutils literal"><span class="pre">unique=True</span></tt> is specified or not.</p>
</div>
</div>
</div>
<div class="section" id="s-sqlite-notes">
<span id="s-id9"></span><span id="sqlite-notes"></span><span id="id9"></span><h2>SQLite notes<a class="headerlink" href="#sqlite-notes" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="http://www.sqlite.org/">SQLite</a> provides an excellent development alternative for applications that
are predominantly read-only or require a smaller installation footprint. As
with all database servers, though, there are some differences that are
specific to SQLite that you should be aware of.</p>
<div class="section" id="s-string-matching-for-non-ascii-strings">
<span id="s-sqlite-string-matching"></span><span id="string-matching-for-non-ascii-strings"></span><span id="sqlite-string-matching"></span><h3>String matching for non-ASCII strings<a class="headerlink" href="#string-matching-for-non-ascii-strings" title="Permalink to this headline">¶</a></h3>
<p>SQLite doesn't support case-insensitive matching for non-ASCII strings. Some
possible workarounds for this are <a class="reference external" href="http://www.sqlite.org/faq.html#q18">documented at sqlite.org</a>, but they are
not utilised by the default SQLite backend in Django. Therefore, if you are
using the <tt class="docutils literal"><span class="pre">iexact</span></tt> lookup type in your queryset filters, be aware that it
will not work as expected for non-ASCII strings.</p>
</div>
<div class="section" id="s-sqlite-3-3-6-or-newer-strongly-recommended">
<span id="sqlite-3-3-6-or-newer-strongly-recommended"></span><h3>SQLite 3.3.6 or newer strongly recommended<a class="headerlink" href="#sqlite-3-3-6-or-newer-strongly-recommended" title="Permalink to this headline">¶</a></h3>
<p>Versions of SQLite 3.3.5 and older contains the following bugs:</p>
<ul class="simple">
<li>A bug when <a class="reference external" href="http://www.sqlite.org/cvstrac/tktview?tn=1768">handling</a> <tt class="docutils literal"><span class="pre">ORDER</span> <span class="pre">BY</span></tt> parameters. This can cause problems when
you use the <tt class="docutils literal"><span class="pre">select</span></tt> parameter for the <tt class="docutils literal"><span class="pre">extra()</span></tt> QuerySet method. The bug
can be identified by the error message <tt class="docutils literal"><span class="pre">OperationalError:</span> <span class="pre">ORDER</span> <span class="pre">BY</span> <span class="pre">terms</span>
<span class="pre">must</span> <span class="pre">not</span> <span class="pre">be</span> <span class="pre">non-integer</span> <span class="pre">constants</span></tt>.</li>
<li>A bug when handling <a class="reference external" href="http://code.djangoproject.com/ticket/10031">aggregation</a> together with DateFields and
DecimalFields.</li>
</ul>
<p>SQLite 3.3.6 was released in April 2006, so most current binary distributions
for different platforms include newer version of SQLite usable from Python
through either the <tt class="docutils literal"><span class="pre">pysqlite2</span></tt> or the <tt class="docutils literal"><span class="pre">sqlite3</span></tt> modules.</p>
<p>However, some platform/Python version combinations include older versions of
SQLite (e.g. the official binary distribution of Python 2.5 for Windows, 2.5.4
as of this writing, includes SQLite 3.3.4). There are (as of Django 1.1) even
some tests in the Django test suite that will fail when run under this setup.</p>
<p>As described <a class="reference internal" href="#using-newer-versions-of-pysqlite"><em>below</em></a>, this can be solved
by downloading and installing a newer version of <tt class="docutils literal"><span class="pre">pysqlite2</span></tt>
(<tt class="docutils literal"><span class="pre">pysqlite-2.x.x.win32-py2.5.exe</span></tt> in the described case) that includes and
uses a newer version of SQLite. Python 2.6 for Windows ships with a version of
SQLite that is not affected by these issues.</p>
</div>
<div class="section" id="s-version-3-5-9">
<span id="version-3-5-9"></span><h3>Version 3.5.9<a class="headerlink" href="#version-3-5-9" title="Permalink to this headline">¶</a></h3>
<p>The Ubuntu &quot;Intrepid Ibex&quot; (8.10) SQLite 3.5.9-3 package contains a bug that
causes problems with the evaluation of query expressions. If you are using
Ubuntu &quot;Intrepid Ibex&quot;, you will need to update the package to version
3.5.9-3ubuntu1 or newer (recommended) or find an alternate source for SQLite
packages, or install SQLite from source.</p>
<p>At one time, Debian Lenny shipped with the same malfunctioning SQLite 3.5.9-3
package. However the Debian project has subsequently issued updated versions
of the SQLite package that correct these bugs. If you find you are getting
unexpected results under Debian, ensure you have updated your SQLite package
to 3.5.9-5 or later.</p>
<p>The problem does not appear to exist with other versions of SQLite packaged
with other operating systems.</p>
</div>
<div class="section" id="s-version-3-6-2">
<span id="version-3-6-2"></span><h3>Version 3.6.2<a class="headerlink" href="#version-3-6-2" title="Permalink to this headline">¶</a></h3>
<p>SQLite version 3.6.2 (released August 30, 2008) introduced a bug into <tt class="docutils literal"><span class="pre">SELECT</span>
<span class="pre">DISTINCT</span></tt> handling that is triggered by, amongst other things, Django's
<tt class="docutils literal"><span class="pre">DateQuerySet</span></tt> (returned by the <tt class="docutils literal"><span class="pre">dates()</span></tt> method on a queryset).</p>
<p>You should avoid using this version of SQLite with Django. Either upgrade to
3.6.3 (released September 22, 2008) or later, or downgrade to an earlier
version of SQLite.</p>
</div>
<div class="section" id="s-using-newer-versions-of-the-sqlite-db-api-2-0-driver">
<span id="s-using-newer-versions-of-pysqlite"></span><span id="using-newer-versions-of-the-sqlite-db-api-2-0-driver"></span><span id="using-newer-versions-of-pysqlite"></span><h3>Using newer versions of the SQLite DB-API 2.0 driver<a class="headerlink" href="#using-newer-versions-of-the-sqlite-db-api-2-0-driver" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<span class="title">New in Django 1.1:</span> <a class="reference internal" href="../releases/1.1.html"><em>Please, see the release notes</em></a></div>
<p>For versions of Python 2.5 or newer that include <tt class="docutils literal"><span class="pre">sqlite3</span></tt> in the standard
library Django will now use a <tt class="docutils literal"><span class="pre">pysqlite2</span></tt> interface in preference to
<tt class="docutils literal"><span class="pre">sqlite3</span></tt> if it finds one is available.</p>
<p>This provides the ability to upgrade both the DB-API 2.0 interface or SQLite 3
itself to versions newer than the ones included with your particular Python
binary distribution, if needed.</p>
</div>
<div class="section" id="s-database-is-locked-errors">
<span id="database-is-locked-errors"></span><h3>&quot;Database is locked&quot; errors<a class="headerlink" href="#database-is-locked-errors" title="Permalink to this headline">¶</a></h3>
<p>SQLite is meant to be a lightweight database, and thus can't support a high
level of concurrency. <tt class="docutils literal"><span class="pre">OperationalError:</span> <span class="pre">database</span> <span class="pre">is</span> <span class="pre">locked</span></tt> errors indicate
that your application is experiencing more concurrency than <tt class="docutils literal"><span class="pre">sqlite</span></tt> can
handle in default configuration. This error means that one thread or process has
an exclusive lock on the database connection and another thread timed out
waiting for the lock the be released.</p>
<p>Python's SQLite wrapper has
a default timeout value that determines how long the second thread is allowed to
wait on the lock before it times out and raises the <tt class="docutils literal"><span class="pre">OperationalError:</span> <span class="pre">database</span>
<span class="pre">is</span> <span class="pre">locked</span></tt> error.</p>
<p>If you're getting this error, you can solve it by:</p>
<ul>
<li><p class="first">Switching to another database backend. At a certain point SQLite becomes
too &quot;lite&quot; for real-world applications, and these sorts of concurrency
errors indicate you've reached that point.</p>
</li>
<li><p class="first">Rewriting your code to reduce concurrency and ensure that database
transactions are short-lived.</p>
</li>
<li><p class="first">Increase the default timeout value by setting the <tt class="docutils literal"><span class="pre">timeout</span></tt> database
option option:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">OPTIONS</span> <span class="o">=</span> <span class="p">{</span>
    <span class="c"># ...</span>
   <span class="s">&quot;timeout&quot;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span>
    <span class="c"># ...</span>
<span class="p">}</span>
</pre></div>
</div>
<p>This will simply make SQLite wait a bit longer before throwing &quot;database
is locked&quot; errors; it won't really do anything to solve them.</p>
</li>
</ul>
</div>
</div>
<div class="section" id="s-oracle-notes">
<span id="s-id10"></span><span id="oracle-notes"></span><span id="id10"></span><h2>Oracle notes<a class="headerlink" href="#oracle-notes" title="Permalink to this headline">¶</a></h2>
<p>Django supports <a class="reference external" href="http://www.oracle.com/">Oracle Database Server</a> versions 9i and
higher. Oracle version 10g or later is required to use Django's
<tt class="docutils literal"><span class="pre">regex</span></tt> and <tt class="docutils literal"><span class="pre">iregex</span></tt> query operators. You will also need at least
version 4.3.1 of the <a class="reference external" href="http://cx-oracle.sourceforge.net/">cx_Oracle</a> Python driver.</p>
<p>Note that due to a Unicode-corruption bug in <tt class="docutils literal"><span class="pre">cx_Oracle</span></tt> 5.0, that
version of the driver should <strong>not</strong> be used with Django;
<tt class="docutils literal"><span class="pre">cx_Oracle</span></tt> 5.0.1 resolved this issue, so if you'd like to use a
more recent <tt class="docutils literal"><span class="pre">cx_Oracle</span></tt>, use version 5.0.1.</p>
<p><tt class="docutils literal"><span class="pre">cx_Oracle</span></tt> 5.0.1 or greater can optionally be compiled with the
<tt class="docutils literal"><span class="pre">WITH_UNICODE</span></tt> environment variable.  This is recommended but not
required.</p>
<p>In order for the <tt class="docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">syncdb</span></tt> command to work, your Oracle
database user must have privileges to run the following commands:</p>
<ul class="simple">
<li>CREATE TABLE</li>
<li>CREATE SEQUENCE</li>
<li>CREATE PROCEDURE</li>
<li>CREATE TRIGGER</li>
</ul>
<p>To run Django's test suite, the user needs these <em>additional</em> privileges:</p>
<ul class="simple">
<li>CREATE USER</li>
<li>DROP USER</li>
<li>CREATE TABLESPACE</li>
<li>DROP TABLESPACE</li>
<li>CONNECT WITH ADMIN OPTION</li>
<li>RESOURCE WITH ADMIN OPTION</li>
</ul>
<div class="section" id="s-id11">
<span id="id11"></span><h3>Connecting to the database<a class="headerlink" href="#id11" title="Permalink to this headline">¶</a></h3>
<p>Your Django settings.py file should look something like this for Oracle:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">DATABASES</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;default&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s">&#39;ENGINE&#39;</span><span class="p">:</span> <span class="s">&#39;django.db.backends.oracle&#39;</span><span class="p">,</span>
        <span class="s">&#39;NAME&#39;</span><span class="p">:</span> <span class="s">&#39;xe&#39;</span><span class="p">,</span>
        <span class="s">&#39;USER&#39;</span><span class="p">:</span> <span class="s">&#39;a_user&#39;</span><span class="p">,</span>
        <span class="s">&#39;PASSWORD&#39;</span><span class="p">:</span> <span class="s">&#39;a_password&#39;</span><span class="p">,</span>
        <span class="s">&#39;HOST&#39;</span><span class="p">:</span> <span class="s">&#39;&#39;</span><span class="p">,</span>
        <span class="s">&#39;PORT&#39;</span><span class="p">:</span> <span class="s">&#39;&#39;</span>     <span class="p">,</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>If you don't use a <tt class="docutils literal"><span class="pre">tnsnames.ora</span></tt> file or a similar naming method that
recognizes the SID (&quot;xe&quot; in this example), then fill in both
<tt class="docutils literal"><span class="pre">HOST</span></tt> and <tt class="docutils literal"><span class="pre">PORT</span></tt> like so:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">DATABASES</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;default&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s">&#39;ENGINE&#39;</span><span class="p">:</span> <span class="s">&#39;django.db.backends.oracle&#39;</span><span class="p">,</span>
        <span class="s">&#39;NAME&#39;</span><span class="p">:</span> <span class="s">&#39;xe&#39;</span><span class="p">,</span>
        <span class="s">&#39;USER&#39;</span><span class="p">:</span> <span class="s">&#39;a_user&#39;</span><span class="p">,</span>
        <span class="s">&#39;PASSWORD&#39;</span><span class="p">:</span> <span class="s">&#39;a_password&#39;</span><span class="p">,</span>
        <span class="s">&#39;HOST&#39;</span><span class="p">:</span> <span class="s">&#39;dbprod01ned.mycompany.com&#39;</span><span class="p">,</span>
        <span class="s">&#39;PORT&#39;</span><span class="p">:</span> <span class="s">&#39;1540&#39;</span><span class="p">,</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>You should supply both <tt class="docutils literal"><span class="pre">HOST</span></tt> and <tt class="docutils literal"><span class="pre">PORT</span></tt>, or leave both
as empty strings.</p>
</div>
<div class="section" id="s-tablespace-options">
<span id="tablespace-options"></span><h3>Tablespace options<a class="headerlink" href="#tablespace-options" title="Permalink to this headline">¶</a></h3>
<p>A common paradigm for optimizing performance in Oracle-based systems is the
use of <a class="reference external" href="http://en.wikipedia.org/wiki/Tablespace">tablespaces</a> to organize disk layout. The Oracle backend supports
this use case by adding <tt class="docutils literal"><span class="pre">db_tablespace</span></tt> options to the <tt class="docutils literal"><span class="pre">Meta</span></tt> and
<tt class="docutils literal"><span class="pre">Field</span></tt> classes.  (When you use a backend that lacks support for tablespaces,
Django ignores these options.)</p>
<p>A tablespace can be specified for the table(s) generated by a model by
supplying the <tt class="docutils literal"><span class="pre">db_tablespace</span></tt> option inside the model's <tt class="docutils literal"><span class="pre">class</span> <span class="pre">Meta</span></tt>.
Additionally, you can pass the <tt class="docutils literal"><span class="pre">db_tablespace</span></tt> option to a <tt class="docutils literal"><span class="pre">Field</span></tt>
constructor to specify an alternate tablespace for the <tt class="docutils literal"><span class="pre">Field</span></tt>'s column
index. If no index would be created for the column, the <tt class="docutils literal"><span class="pre">db_tablespace</span></tt>
option is ignored:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">TablespaceExample</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">db_index</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">db_tablespace</span><span class="o">=</span><span class="s">&quot;indexes&quot;</span><span class="p">)</span>
    <span class="n">data</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">255</span><span class="p">,</span> <span class="n">db_index</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">edges</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ManyToManyField</span><span class="p">(</span><span class="n">to</span><span class="o">=</span><span class="s">&quot;self&quot;</span><span class="p">,</span> <span class="n">db_tablespace</span><span class="o">=</span><span class="s">&quot;indexes&quot;</span><span class="p">)</span>

    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
        <span class="n">db_tablespace</span> <span class="o">=</span> <span class="s">&quot;tables&quot;</span>
</pre></div>
</div>
<p>In this example, the tables generated by the <tt class="docutils literal"><span class="pre">TablespaceExample</span></tt> model
(i.e., the model table and the many-to-many table) would be stored in the
<tt class="docutils literal"><span class="pre">tables</span></tt> tablespace. The index for the name field and the indexes on the
many-to-many table would be stored in the <tt class="docutils literal"><span class="pre">indexes</span></tt> tablespace. The <tt class="docutils literal"><span class="pre">data</span></tt>
field would also generate an index, but no tablespace for it is specified, so
it would be stored in the model tablespace <tt class="docutils literal"><span class="pre">tables</span></tt> by default.</p>
<div class="versionadded">
<span class="title">New in Django 1.0:</span> <a class="reference internal" href="../releases/1.0.html"><em>Please, see the release notes</em></a></div>
<p>Use the <a class="reference internal" href="settings.html#std:setting-DEFAULT_TABLESPACE"><tt class="xref std std-setting docutils literal"><span class="pre">DEFAULT_TABLESPACE</span></tt></a> and <a class="reference internal" href="settings.html#std:setting-DEFAULT_INDEX_TABLESPACE"><tt class="xref std std-setting docutils literal"><span class="pre">DEFAULT_INDEX_TABLESPACE</span></tt></a>
settings to specify default values for the db_tablespace options.
These are useful for setting a tablespace for the built-in Django apps and
other applications whose code you cannot control.</p>
<p>Django does not create the tablespaces for you. Please refer to <a class="reference external" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7003.htm#SQLRF01403">Oracle's
documentation</a> for details on creating and managing tablespaces.</p>
</div>
<div class="section" id="s-naming-issues">
<span id="naming-issues"></span><h3>Naming issues<a class="headerlink" href="#naming-issues" title="Permalink to this headline">¶</a></h3>
<p>Oracle imposes a name length limit of 30 characters. To accommodate this, the
backend truncates database identifiers to fit, replacing the final four
characters of the truncated name with a repeatable MD5 hash value.</p>
<p>When running syncdb, an <tt class="docutils literal"><span class="pre">ORA-06552</span></tt> error may be encountered if
certain Oracle keywords are used as the name of a model field or the
value of a <tt class="docutils literal"><span class="pre">db_column</span></tt> option.  Django quotes all identifiers used
in queries to prevent most such problems, but this error can still
occur when an Oracle datatype is used as a column name.  In
particular, take care to avoid using the names <tt class="docutils literal"><span class="pre">date</span></tt>,
<tt class="docutils literal"><span class="pre">timestamp</span></tt>, <tt class="docutils literal"><span class="pre">number</span></tt> or <tt class="docutils literal"><span class="pre">float</span></tt> as a field name.</p>
</div>
<div class="section" id="s-null-and-empty-strings">
<span id="null-and-empty-strings"></span><h3>NULL and empty strings<a class="headerlink" href="#null-and-empty-strings" title="Permalink to this headline">¶</a></h3>
<p>Django generally prefers to use the empty string ('') rather than
NULL, but Oracle treats both identically. To get around this, the
Oracle backend coerces the <tt class="docutils literal"><span class="pre">null=True</span></tt> option on fields that have
the empty string as a possible value. When fetching from the database,
it is assumed that a NULL value in one of these fields really means
the empty string, and the data is silently converted to reflect this
assumption.</p>
</div>
<div class="section" id="s-textfield-limitations">
<span id="textfield-limitations"></span><h3><tt class="docutils literal"><span class="pre">TextField</span></tt> limitations<a class="headerlink" href="#textfield-limitations" title="Permalink to this headline">¶</a></h3>
<p>The Oracle backend stores <tt class="docutils literal"><span class="pre">TextFields</span></tt> as <tt class="docutils literal"><span class="pre">NCLOB</span></tt> columns. Oracle imposes
some limitations on the usage of such LOB columns in general:</p>
<ul class="simple">
<li>LOB columns may not be used as primary keys.</li>
<li>LOB columns may not be used in indexes.</li>
<li>LOB columns may not be used in a <tt class="docutils literal"><span class="pre">SELECT</span> <span class="pre">DISTINCT</span></tt> list. This means that
attempting to use the <tt class="docutils literal"><span class="pre">QuerySet.distinct</span></tt> method on a model that
includes <tt class="docutils literal"><span class="pre">TextField</span></tt> columns will result in an error when run against
Oracle. A workaround to this is to keep <tt class="docutils literal"><span class="pre">TextField</span></tt> columns out of any
models that you foresee performing <tt class="docutils literal"><span class="pre">distinct()</span></tt> queries on, and to
include the <tt class="docutils literal"><span class="pre">TextField</span></tt> in a related model instead.</li>
</ul>
</div>
</div>
<div class="section" id="s-using-a-3rd-party-database-backend">
<span id="s-third-party-notes"></span><span id="using-a-3rd-party-database-backend"></span><span id="third-party-notes"></span><h2>Using a 3rd-party database backend<a class="headerlink" href="#using-a-3rd-party-database-backend" title="Permalink to this headline">¶</a></h2>
<p>In addition to the officially supported databases, there are backends provided
by 3rd parties that allow you to use other databases with Django:</p>
<ul class="simple">
<li><a class="reference external" href="http://code.google.com/p/sqlany-django/">Sybase SQL Anywhere</a></li>
<li><a class="reference external" href="http://code.google.com/p/ibm-db/">IBM DB2</a></li>
<li><a class="reference external" href="http://code.google.com/p/django-mssql/">Microsoft SQL Server 2005</a></li>
<li><a class="reference external" href="http://code.google.com/p/django-firebird/">Firebird</a></li>
<li><a class="reference external" href="http://code.google.com/p/django-pyodbc/">ODBC</a></li>
</ul>
<p>The Django versions and ORM features supported by these unofficial backends
vary considerably. Queries regarding the specific capabilities of these
unofficial backends, along with any support queries, should be directed to
the support channels provided by each 3rd party project.</p>
</div>
</div>


          </div>         
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Databases</a><ul>
<li><a class="reference internal" href="#postgresql-notes">PostgreSQL notes</a><ul>
<li><a class="reference internal" href="#postgresql-8-2-to-8-2-4">PostgreSQL 8.2 to 8.2.4</a></li>
<li><a class="reference internal" href="#transaction-handling">Transaction handling</a><ul>
<li><a class="reference internal" href="#autocommit-mode">Autocommit mode</a></li>
<li><a class="reference internal" href="#indexes-for-varchar-and-text-columns">Indexes for <tt class="docutils literal"><span class="pre">varchar</span></tt> and <tt class="docutils literal"><span class="pre">text</span></tt> columns</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#mysql-notes">MySQL notes</a><ul>
<li><a class="reference internal" href="#mysql-4-1">MySQL 4.1</a></li>
<li><a class="reference internal" href="#mysql-5-0">MySQL 5.0</a></li>
<li><a class="reference internal" href="#storage-engines">Storage engines</a></li>
<li><a class="reference internal" href="#mysqldb">MySQLdb</a></li>
<li><a class="reference internal" href="#creating-your-database">Creating your database</a><ul>
<li><a class="reference internal" href="#collation-settings">Collation settings</a></li>
</ul>
</li>
<li><a class="reference internal" href="#connecting-to-the-database">Connecting to the database</a></li>
<li><a class="reference internal" href="#creating-your-tables">Creating your tables</a></li>
<li><a class="reference internal" href="#notes-on-specific-fields">Notes on specific fields</a><ul>
<li><a class="reference internal" href="#boolean-fields">Boolean fields</a></li>
<li><a class="reference internal" href="#character-fields">Character fields</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#sqlite-notes">SQLite notes</a><ul>
<li><a class="reference internal" href="#string-matching-for-non-ascii-strings">String matching for non-ASCII strings</a></li>
<li><a class="reference internal" href="#sqlite-3-3-6-or-newer-strongly-recommended">SQLite 3.3.6 or newer strongly recommended</a></li>
<li><a class="reference internal" href="#version-3-5-9">Version 3.5.9</a></li>
<li><a class="reference internal" href="#version-3-6-2">Version 3.6.2</a></li>
<li><a class="reference internal" href="#using-newer-versions-of-the-sqlite-db-api-2-0-driver">Using newer versions of the SQLite DB-API 2.0 driver</a></li>
<li><a class="reference internal" href="#database-is-locked-errors">&#8220;Database is locked&#8221; errors</a></li>
</ul>
</li>
<li><a class="reference internal" href="#oracle-notes">Oracle notes</a><ul>
<li><a class="reference internal" href="#id11">Connecting to the database</a></li>
<li><a class="reference internal" href="#tablespace-options">Tablespace options</a></li>
<li><a class="reference internal" href="#naming-issues">Naming issues</a></li>
<li><a class="reference internal" href="#null-and-empty-strings">NULL and empty strings</a></li>
<li><a class="reference internal" href="#textfield-limitations"><tt class="docutils literal"><span class="pre">TextField</span></tt> limitations</a></li>
</ul>
</li>
<li><a class="reference internal" href="#using-a-3rd-party-database-backend">Using a 3rd-party database backend</a></li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="contrib/webdesign.html">django.contrib.webdesign</a></li>
    
    
      <li>Next: <a href="django-admin.html">django-admin.py and manage.py</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../index.html">Django v1.2 documentation</a>
        
          <ul><li><a href="index.html">API Reference</a>
        
        <ul><li>Databases</li></ul>
        </li></ul>
      </li>
  </ul>  

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/ref/databases.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Oct 20, 2010</p>
          </div> 
        
      
    </div>
    
    <div id="ft">
      <div class="nav">
    &laquo; <a href="contrib/webdesign.html" title="django.contrib.webdesign">previous</a> 
     |
    <a href="index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="django-admin.html" title="django-admin.py and manage.py">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>