{"title":"Databases","version":"6.0","locale":"pl","docname":"ref/databases","url":"/pl/6.0/ref/databases/","canonical":"https://djangodocs.dev/pl/6.0/ref/databases/","summary":"Django officially supports the following databases: PostgreSQL MariaDB MySQL Oracle SQLite There are also a number of database backends provided by third parties .…","html":"<h1>Databases<a class=\"heading-anchor\" href=\"#databases\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Django officially supports the following databases:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#postgresql-notes\"><span class=\"std std-ref\">PostgreSQL</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#mariadb-notes\"><span class=\"std std-ref\">MariaDB</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#mysql-notes\"><span class=\"std std-ref\">MySQL</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#oracle-notes\"><span class=\"std std-ref\">Oracle</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#sqlite-notes\"><span class=\"std std-ref\">SQLite</span></a></p></li>\n</ul>\n<p>There are also a number of <a class=\"reference internal\" href=\"#third-party-notes\"><span class=\"std std-ref\">database backends provided by third parties</span></a>.</p>\n<p>Django attempts to support as many features as possible on all database\nbackends. However, not all database backends are alike, and we’ve had to make\ndesign decisions on which features to support and which assumptions we can make\nsafely.</p>\n<p>This file describes some of the features that might be relevant to Django\nusage. It is not intended as a replacement for server-specific documentation or\nreference manuals.</p>\n<section id=\"general-notes\">\n<h2>General notes<a class=\"heading-anchor\" href=\"#general-notes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"persistent-connections\">\n<span id=\"persistent-database-connections\"></span><h3>Persistent connections<a class=\"heading-anchor\" href=\"#persistent-connections\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Persistent connections avoid the overhead of reestablishing a connection to\nthe database in each HTTP request. They’re controlled by the\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-CONN_MAX_AGE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CONN_MAX_AGE</span></code></a> parameter which defines the maximum lifetime of a\nconnection. It can be set independently for each database.</p>\n<p>The default value is <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code>, preserving the historical behavior of closing the\ndatabase connection at the end of each request. To enable persistent\nconnections, set <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-CONN_MAX_AGE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CONN_MAX_AGE</span></code></a> to a positive integer of seconds. For\nunlimited persistent connections, set it to <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>.</p>\n<p>When using ASGI, persistent connections should be disabled. Instead, use your\ndatabase backend’s built-in connection pooling if available, or investigate a\nthird-party connection pooling option if required.</p>\n<section id=\"connection-management\">\n<h4>Connection management<a class=\"heading-anchor\" href=\"#connection-management\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Django opens a connection to the database when it first makes a database\nquery. It keeps this connection open and reuses it in subsequent requests.\nDjango closes the connection once it exceeds the maximum age defined by\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-CONN_MAX_AGE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CONN_MAX_AGE</span></code></a> or when it isn’t usable any longer.</p>\n<p>In detail, Django automatically opens a connection to the database whenever it\nneeds one and doesn’t have one already — either because this is the first\nconnection, or because the previous connection was closed.</p>\n<p>At the beginning of each request, Django closes the connection if it has\nreached its maximum age. If your database terminates idle connections after\nsome time, you should set <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-CONN_MAX_AGE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CONN_MAX_AGE</span></code></a> to a lower value, so that\nDjango doesn’t attempt to use a connection that has been terminated by the\ndatabase server. (This problem may only affect very low traffic sites.)</p>\n<p>At the end of each request, Django closes the connection if it has reached its\nmaximum age or if it is in an unrecoverable error state. If any database\nerrors have occurred while processing the requests, Django checks whether the\nconnection still works, and closes it if it doesn’t. Thus, database errors\naffect at most one request per each application’s worker thread; if the\nconnection becomes unusable, the next request gets a fresh connection.</p>\n<p>Setting <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-CONN_HEALTH_CHECKS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CONN_HEALTH_CHECKS</span></code></a> to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> can be used to improve the\nrobustness of connection reuse and prevent errors when a connection has been\nclosed by the database server which is now ready to accept and serve new\nconnections, e.g. after database server restart. The health check is performed\nonly once per request and only if the database is being accessed during the\nhandling of the request.</p>\n</section>\n<section id=\"caveats\">\n<h4>Caveats<a class=\"heading-anchor\" href=\"#caveats\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Since each thread maintains its own connection, your database must support at\nleast as many simultaneous connections as you have worker threads.</p>\n<p>Sometimes a database won’t be accessed by the majority of your views, for\nexample because it’s the database of an external system, or thanks to caching.\nIn such cases, you should set <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-CONN_MAX_AGE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CONN_MAX_AGE</span></code></a> to a low value or even\n<code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code>, because it doesn’t make sense to maintain a connection that’s unlikely\nto be reused. This will help keep the number of simultaneous connections to\nthis database small.</p>\n<p>The development server creates a new thread for each request it handles,\nnegating the effect of persistent connections. Don’t enable them during\ndevelopment.</p>\n<p>When Django establishes a connection to the database, it sets up appropriate\nparameters, depending on the backend being used. If you enable persistent\nconnections, this setup is no longer repeated every request. If you modify\nparameters such as the connection’s isolation level or time zone, you should\neither restore Django’s defaults at the end of each request, force an\nappropriate value at the beginning of each request, or disable persistent\nconnections.</p>\n<p>If a connection is created in a long-running process, outside of Django’s\nrequest-response cycle, the connection will remain open until explicitly\nclosed, or timeout occurs. You can use <code class=\"docutils literal notranslate\"><span class=\"pre\">django.db.close_old_connections()</span></code> to\nclose all old or unusable connections.</p>\n</section>\n</section>\n<section id=\"encoding\">\n<h3>Encoding<a class=\"heading-anchor\" href=\"#encoding\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django assumes that all databases use UTF-8 encoding. Using other encodings may\nresult in unexpected behavior such as „value too long” errors from your\ndatabase for data that is valid in Django. See the database specific notes\nbelow for information on how to set up your database correctly.</p>\n</section>\n</section>\n<section id=\"postgresql-notes\">\n<span id=\"id1\"></span><h2>PostgreSQL notes<a class=\"heading-anchor\" href=\"#postgresql-notes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django supports PostgreSQL 14 and higher. <a class=\"reference external\" href=\"https://www.psycopg.org/psycopg3/\">psycopg</a> 3.1.12+ or <a class=\"reference external\" href=\"https://www.psycopg.org/\">psycopg2</a>\n2.9.9+ is required, though the latest <a class=\"reference external\" href=\"https://www.psycopg.org/psycopg3/\">psycopg</a> 3.1.12+ is recommended.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Informacja</p>\n<p>Support for <code class=\"docutils literal notranslate\"><span class=\"pre\">psycopg2</span></code> is likely to be deprecated and removed at some\npoint in the future.</p>\n</aside>\n<section id=\"postgresql-connection-settings\">\n<span id=\"id2\"></span><h3>PostgreSQL connection settings<a class=\"heading-anchor\" href=\"#postgresql-connection-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>See <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">HOST</span></code></a> for details.</p>\n<p>To connect using a service name from the <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/libpq-pgservice.html\">connection service file</a> and a\npassword from the <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/libpq-pgpass.html\">password file</a>, you must specify them in the\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> part of your database configuration in <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a>:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.postgresql&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;service&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;my_service&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;passfile&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;.my_pgpass&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></figure>\n<figure class=\"code-block code-block-captioned\" data-language=\"text\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">.pg_service.conf</span></code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>[my_service]\nhost=localhost\nuser=USER\ndbname=NAME\nport=5432\n</code></pre></figure>\n<figure class=\"code-block code-block-captioned\" data-language=\"text\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">.my_pgpass</span></code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>localhost:5432:NAME:USER:PASSWORD\n</code></pre></figure>\n<p>The PostgreSQL backend passes the content of <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> as keyword\narguments to the connection constructor, allowing for more advanced control\nof driver behavior. All available <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS\">parameters</a> are described in detail in the\nPostgreSQL documentation.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Ostrzeżenie</p>\n<p>Using a service name for testing purposes is not supported. This\n<a class=\"extlink-ticket reference external\" href=\"https://code.djangoproject.com/ticket/33685\">may be implemented later</a>.</p>\n</aside>\n</section>\n<section id=\"optimizing-postgresql-s-configuration\">\n<h3>Optimizing PostgreSQL’s configuration<a class=\"heading-anchor\" href=\"#optimizing-postgresql-s-configuration\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django needs the following parameters for its database connections:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">client_encoding</span></code>: <code class=\"docutils literal notranslate\"><span class=\"pre\">'UTF8'</span></code>,</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">default_transaction_isolation</span></code>: <code class=\"docutils literal notranslate\"><span class=\"pre\">'read</span> <span class=\"pre\">committed'</span></code> by default,\nor the value set in the connection options (see below),</p></li>\n<li><dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">timezone</span></code>:</dt><dd><ul>\n<li><p>when <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-USE_TZ\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_TZ</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">'UTC'</span></code> by default, or the\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASE-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code></a> value set for the connection,</p></li>\n<li><p>when <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-USE_TZ\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_TZ</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>, the value of the global\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code></a> setting.</p></li>\n</ul>\n</dd>\n</dl>\n</li>\n</ul>\n<p>If these parameters already have the correct values, Django won’t set them for\nevery new connection, which improves performance slightly. You can configure\nthem directly in <code class=\"file docutils literal notranslate\"><span class=\"pre\">postgresql.conf</span></code> or more conveniently per database\nuser with <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/sql-alterrole.html\">ALTER ROLE</a>.</p>\n<p>Django will work just fine without this optimization, but each new connection\nwill do some additional queries to set these parameters.</p>\n</section>\n<section id=\"isolation-level\">\n<span id=\"database-isolation-level\"></span><h3>Isolation level<a class=\"heading-anchor\" href=\"#isolation-level\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Like PostgreSQL itself, Django defaults to the <code class=\"docutils literal notranslate\"><span class=\"pre\">READ</span> <span class=\"pre\">COMMITTED</span></code> <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/transaction-iso.html\">isolation\nlevel</a>. If you need a higher isolation level such as <code class=\"docutils literal notranslate\"><span class=\"pre\">REPEATABLE</span> <span class=\"pre\">READ</span></code> or\n<code class=\"docutils literal notranslate\"><span class=\"pre\">SERIALIZABLE</span></code>, set it in the <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> part of your database\nconfiguration in <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.db.backends.postgresql.psycopg_any</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">IsolationLevel</span>\n\n<span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;isolation_level&quot;</span><span class=\"p\">:</span> <span class=\"n\">IsolationLevel</span><span class=\"o\">.</span><span class=\"n\">SERIALIZABLE</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Informacja</p>\n<p>Under higher isolation levels, your application should be prepared to\nhandle exceptions raised on serialization failures. This option is\ndesigned for advanced uses.</p>\n</aside>\n</section>\n<section id=\"role\">\n<span id=\"database-role\"></span><h3>Role<a class=\"heading-anchor\" href=\"#role\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you need to use a different role for database connections than the role used\nto establish the connection, set it in the <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> part of your\ndatabase configuration in <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.postgresql&quot;</span><span class=\"p\">,</span>\n        <span class=\"c1\"># ...</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;assume_role&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;my_application_role&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n</section>\n<section id=\"connection-pool\">\n<span id=\"postgresql-pool\"></span><h3>Connection pool<a class=\"heading-anchor\" href=\"#connection-pool\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>To use a connection pool with <a class=\"reference external\" href=\"https://www.psycopg.org/psycopg3/\">psycopg</a>, you can either set <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;pool&quot;</span></code> in the\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> part of your database configuration in <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a>\nto be a dict to be passed to <a class=\"reference external\" href=\"https://www.psycopg.org/psycopg3/docs/api/pool.html#psycopg_pool.ConnectionPool\" title=\" (w psycopg)\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ConnectionPool</span></code></a>, or\nto <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> to use the <code class=\"docutils literal notranslate\"><span class=\"pre\">ConnectionPool</span></code> defaults:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.postgresql&quot;</span><span class=\"p\">,</span>\n        <span class=\"c1\"># ...</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;pool&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>This option requires <code class=\"docutils literal notranslate\"><span class=\"pre\">psycopg[pool]</span></code> or <a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/psycopg-pool/\">psycopg-pool</a> to be installed\nand is ignored with <code class=\"docutils literal notranslate\"><span class=\"pre\">psycopg2</span></code>.</p>\n</section>\n<section id=\"server-side-parameters-binding\">\n<span id=\"database-server-side-parameters-binding\"></span><h3>Server-side parameters binding<a class=\"heading-anchor\" href=\"#server-side-parameters-binding\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>With <a class=\"reference external\" href=\"https://www.psycopg.org/psycopg3/\">psycopg</a> 3.1.8+, Django defaults to the <a class=\"reference external\" href=\"https://www.psycopg.org/psycopg3/docs/advanced/cursors.html#client-side-binding-cursors\" title=\" (w psycopg)\"><span class=\"xref std std-ref\">client-side binding\ncursors</span></a>. If you want to use the\n<a class=\"reference external\" href=\"https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html#server-side-binding\" title=\" (w psycopg)\"><span class=\"xref std std-ref\">server-side binding</span></a> set it in the\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> part of your database configuration in\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.postgresql&quot;</span><span class=\"p\">,</span>\n        <span class=\"c1\"># ...</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;server_side_binding&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>This option is ignored with <code class=\"docutils literal notranslate\"><span class=\"pre\">psycopg2</span></code>.</p>\n</section>\n<section id=\"indexes-for-varchar-and-text-columns\">\n<h3>Indexes for <code class=\"docutils literal notranslate\"><span class=\"pre\">varchar</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">text</span></code> columns<a class=\"heading-anchor\" href=\"#indexes-for-varchar-and-text-columns\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>When specifying <code class=\"docutils literal notranslate\"><span class=\"pre\">db_index=True</span></code> on your model fields, Django typically\noutputs a single <code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">INDEX</span></code> statement. However, if the database type\nfor the field is either <code class=\"docutils literal notranslate\"><span class=\"pre\">varchar</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">text</span></code> (e.g., used by <code class=\"docutils literal notranslate\"><span class=\"pre\">CharField</span></code>,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">FileField</span></code>, and <code class=\"docutils literal notranslate\"><span class=\"pre\">TextField</span></code>), then Django will create\nan additional index that uses an appropriate <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/indexes-opclass.html\">PostgreSQL operator class</a>\nfor the column. The extra index is necessary to correctly perform\nlookups that use the <code class=\"docutils literal notranslate\"><span class=\"pre\">LIKE</span></code> operator in their SQL, as is done with the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">contains</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">startswith</span></code> lookup types.</p>\n</section>\n<section id=\"migration-operation-for-adding-extensions\">\n<h3>Migration operation for adding extensions<a class=\"heading-anchor\" href=\"#migration-operation-for-adding-extensions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you need to add a PostgreSQL extension (like <code class=\"docutils literal notranslate\"><span class=\"pre\">hstore</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">postgis</span></code>, etc.)\nusing a migration, use the\n<a class=\"reference internal\" href=\"/pl/6.0/ref/contrib/postgres/operations/#django.contrib.postgres.operations.CreateExtension\" title=\"django.contrib.postgres.operations.CreateExtension\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CreateExtension</span></code></a> operation.</p>\n</section>\n<section id=\"server-side-cursors\">\n<span id=\"postgresql-server-side-cursors\"></span><h3>Server-side cursors<a class=\"heading-anchor\" href=\"#server-side-cursors\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>When using <a class=\"reference internal\" href=\"/pl/6.0/ref/models/querysets/#django.db.models.query.QuerySet.iterator\" title=\"django.db.models.query.QuerySet.iterator\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">QuerySet.iterator()</span></code></a>, Django opens a <a class=\"reference external\" href=\"https://www.psycopg.org/psycopg3/docs/advanced/cursors.html#server-side-cursors\" title=\" (w psycopg)\"><span class=\"xref std std-ref\">server-side\ncursor</span></a>. By default, PostgreSQL assumes that\nonly the first 10% of the results of cursor queries will be fetched. The query\nplanner spends less time planning the query and starts returning results\nfaster, but this could diminish performance if more than 10% of the results are\nretrieved. PostgreSQL’s assumptions on the number of rows retrieved for a\ncursor query is controlled with the <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/runtime-config-query.html#GUC-CURSOR-TUPLE-FRACTION\">cursor_tuple_fraction</a> option.</p>\n<section id=\"transaction-pooling-and-server-side-cursors\">\n<span id=\"transaction-pooling-server-side-cursors\"></span><h4>Transaction pooling and server-side cursors<a class=\"heading-anchor\" href=\"#transaction-pooling-and-server-side-cursors\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Using a connection pooler in transaction pooling mode (e.g. <a class=\"reference external\" href=\"https://www.pgbouncer.org/\">PgBouncer</a>)\nrequires disabling server-side cursors for that connection.</p>\n<p>Server-side cursors are local to a connection and remain open at the end of a\ntransaction when <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASE-AUTOCOMMIT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">AUTOCOMMIT</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>. A\nsubsequent transaction may attempt to fetch more results from a server-side\ncursor. In transaction pooling mode, there’s no guarantee that subsequent\ntransactions will use the same connection. If a different connection is used,\nan error is raised when the transaction references the server-side cursor,\nbecause server-side cursors are only accessible in the connection in which they\nwere created.</p>\n<p>One solution is to disable server-side cursors for a connection in\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a> by setting <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASE-DISABLE_SERVER_SIDE_CURSORS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DISABLE_SERVER_SIDE_CURSORS</span></code></a> to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n<p>To benefit from server-side cursors in transaction pooling mode, you could set\nup <a class=\"reference internal\" href=\"/pl/6.0/topics/db/multi-db/\"><span class=\"doc\">another connection to the database</span></a> in order to\nperform queries that use server-side cursors. This connection needs to either\nbe directly to the database or to a connection pooler in session pooling mode.</p>\n<p>Another option is to wrap each <code class=\"docutils literal notranslate\"><span class=\"pre\">QuerySet</span></code> using server-side cursors in an\n<a class=\"reference internal\" href=\"/pl/6.0/topics/db/transactions/#django.db.transaction.atomic\" title=\"django.db.transaction.atomic\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">atomic()</span></code></a> block, because it disables <code class=\"docutils literal notranslate\"><span class=\"pre\">autocommit</span></code>\nfor the duration of the transaction. This way, the server-side cursor will only\nlive for the duration of the transaction.</p>\n</section>\n</section>\n<section id=\"manually-specifying-values-of-auto-incrementing-primary-keys\">\n<span id=\"manually-specified-autoincrement-pk\"></span><h3>Manually-specifying values of auto-incrementing primary keys<a class=\"heading-anchor\" href=\"#manually-specifying-values-of-auto-incrementing-primary-keys\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django uses PostgreSQL’s identity columns to store auto-incrementing primary\nkeys. An identity column is populated with values from a <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/sql-createsequence.html\">sequence</a> that keeps\ntrack of the next available value. Manually assigning a value to an\nauto-incrementing field doesn’t update the field’s sequence, which might later\ncause a conflict. For example:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.auth.models</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">User</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">User</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">create</span><span class=\"p\">(</span><span class=\"n\">username</span><span class=\"o\">=</span><span class=\"s2\">&quot;alice&quot;</span><span class=\"p\">,</span> <span class=\"n\">pk</span><span class=\"o\">=</span><span class=\"mi\">1</span><span class=\"p\">)</span>\n<span class=\"go\">&lt;User: alice&gt;</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"c1\"># The sequence hasn&#39;t been updated; its next value is 1.</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">User</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">create</span><span class=\"p\">(</span><span class=\"n\">username</span><span class=\"o\">=</span><span class=\"s2\">&quot;bob&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">IntegrityError: duplicate key value violates unique constraint</span>\n<span class=\"go\">&quot;auth_user_pkey&quot; DETAIL:  Key (id)=(1) already exists.</span>\n</code></pre></div>\n<p>If you need to specify such values, reset the sequence afterward to avoid\nreusing a value that’s already in the table. The <a class=\"reference internal\" href=\"/pl/6.0/ref/django-admin/#django-admin-sqlsequencereset\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">sqlsequencereset</span></code></a>\nmanagement command generates the SQL statements to do that.</p>\n</section>\n<section id=\"test-database-templates\">\n<h3>Test database templates<a class=\"heading-anchor\" href=\"#test-database-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>You can use the <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-TEST_TEMPLATE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TEST['TEMPLATE']</span></code></a> setting to specify\na <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/sql-createdatabase.html\">template</a> (e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">'template0'</span></code>) from which to create a test database.</p>\n</section>\n<section id=\"speeding-up-test-execution-with-non-durable-settings\">\n<h3>Speeding up test execution with non-durable settings<a class=\"heading-anchor\" href=\"#speeding-up-test-execution-with-non-durable-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>You can speed up test execution times by <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/non-durability.html\">configuring PostgreSQL to be\nnon-durable</a>.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Ostrzeżenie</p>\n<p>This is dangerous: it will make your database more susceptible to data loss\nor corruption in the case of a server crash or power loss. Only use this on\na development machine where you can easily restore the entire contents of\nall databases in the cluster.</p>\n</aside>\n</section>\n</section>\n<section id=\"mariadb-notes\">\n<span id=\"id4\"></span><h2>MariaDB notes<a class=\"heading-anchor\" href=\"#mariadb-notes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django supports MariaDB 10.6 and higher.</p>\n<p>To use MariaDB, use the MySQL backend, which is shared between the two. See the\n<a class=\"reference internal\" href=\"#mysql-notes\"><span class=\"std std-ref\">MySQL notes</span></a> for more details.</p>\n</section>\n<section id=\"mysql-notes\">\n<span id=\"id5\"></span><h2>MySQL notes<a class=\"heading-anchor\" href=\"#mysql-notes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"version-support\">\n<h3>Version support<a class=\"heading-anchor\" href=\"#version-support\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django supports MySQL 8.0.11 and higher.</p>\n<p>Django’s <code class=\"docutils literal notranslate\"><span class=\"pre\">inspectdb</span></code> feature uses the <code class=\"docutils literal notranslate\"><span class=\"pre\">information_schema</span></code> database, which\ncontains detailed data on all database schemas.</p>\n<p>Django expects the database to support Unicode (UTF-8 encoding) and delegates\nto it the task of enforcing transactions and referential integrity. It is\nimportant to be aware of the fact that the two latter ones aren’t actually\nenforced by MySQL when using the MyISAM storage engine, see the next section.</p>\n</section>\n<section id=\"storage-engines\">\n<span id=\"mysql-storage-engines\"></span><h3>Storage engines<a class=\"heading-anchor\" href=\"#storage-engines\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>MySQL has several <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/storage-engines.html\">storage engines</a>. You can change the default storage engine\nin the server configuration.</p>\n<p>MySQL’s default storage engine is <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/innodb-storage-engine.html\">InnoDB</a>. This engine is fully transactional\nand supports foreign key references. It’s the recommended choice. However, the\nInnoDB autoincrement counter is lost on a MySQL restart because it does not\nremember the <code class=\"docutils literal notranslate\"><span class=\"pre\">AUTO_INCREMENT</span></code> value, instead recreating it as „max(id)+1”.\nThis may result in an inadvertent reuse of <a class=\"reference internal\" href=\"/pl/6.0/ref/models/fields/#django.db.models.AutoField\" title=\"django.db.models.AutoField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AutoField</span></code></a>\nvalues.</p>\n<p>The main drawbacks of <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/myisam-storage-engine.html\">MyISAM</a> are that it doesn’t support transactions or\nenforce foreign-key constraints.</p>\n</section>\n<section id=\"mysql-db-api-drivers\">\n<span id=\"id7\"></span><h3>MySQL DB API Drivers<a class=\"heading-anchor\" href=\"#mysql-db-api-drivers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>MySQL has a couple drivers that implement the Python Database API described in\n<span class=\"target\" id=\"index-0\"></span><a class=\"pep reference external\" href=\"https://peps.python.org/pep-0249/\"><strong>PEP 249</strong></a>:</p>\n<ul class=\"simple\">\n<li><p><a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/mysqlclient/\">mysqlclient</a> is a native driver. It’s <strong>the recommended choice</strong>.</p></li>\n<li><p><a class=\"reference external\" href=\"https://dev.mysql.com/downloads/connector/python/\">MySQL Connector/Python</a> is a pure Python driver from Oracle that does not\nrequire the MySQL client library or any Python modules outside the standard\nlibrary.</p></li>\n</ul>\n<p>In addition to a DB API driver, Django needs an adapter to access the database\ndrivers from its ORM. Django provides an adapter for mysqlclient while MySQL\nConnector/Python includes <a class=\"reference external\" href=\"https://dev.mysql.com/doc/connector-python/en/connector-python-django-backend.html\">its own</a>.</p>\n<section id=\"mysqlclient\">\n<h4>mysqlclient<a class=\"heading-anchor\" href=\"#mysqlclient\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Django requires <a class=\"reference internal\" href=\"#mysqlclient\">mysqlclient</a> 2.2.1 or later.</p>\n</section>\n<section id=\"id8\">\n<h4>MySQL Connector/Python<a class=\"heading-anchor\" href=\"#id8\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>MySQL Connector/Python is available from the <a class=\"reference external\" href=\"https://dev.mysql.com/downloads/connector/python/\">download page</a>.\nThe Django adapter is available in versions 1.1.X and later. It may not\nsupport the most recent releases of Django.</p>\n</section>\n</section>\n<section id=\"time-zone-definitions\">\n<span id=\"mysql-time-zone-definitions\"></span><h3>Time zone definitions<a class=\"heading-anchor\" href=\"#time-zone-definitions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you plan on using Django’s <a class=\"reference internal\" href=\"/pl/6.0/topics/i18n/timezones/\"><span class=\"doc\">timezone support</span></a>,\nuse <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/mysql-tzinfo-to-sql.html\">mysql_tzinfo_to_sql</a> to load time zone tables into the MySQL database.\nThis needs to be done just once for your MySQL server, not per database.</p>\n</section>\n<section id=\"creating-your-database\">\n<h3>Creating your database<a class=\"heading-anchor\" href=\"#creating-your-database\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>You can <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/create-database.html\">create your database</a> using the command-line tools and this SQL:</p>\n<div class=\"code-block\" data-language=\"sql\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">SQL</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"SQL code\"><code><span class=\"k\">CREATE</span><span class=\"w\"> </span><span class=\"k\">DATABASE</span><span class=\"w\"> </span><span class=\"o\">&lt;</span><span class=\"n\">dbname</span><span class=\"o\">&gt;</span><span class=\"w\"> </span><span class=\"nb\">CHARACTER</span><span class=\"w\"> </span><span class=\"k\">SET</span><span class=\"w\"> </span><span class=\"n\">utf8mb4</span><span class=\"p\">;</span>\n</code></pre></div>\n<p>This ensures all tables and columns will use UTF-8 by default.</p>\n<section id=\"collation-settings\">\n<span id=\"mysql-collation\"></span><h4>Collation settings<a class=\"heading-anchor\" href=\"#collation-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The collation setting for a column controls the order in which data is sorted\nas well as what strings compare as equal. You can specify the <code class=\"docutils literal notranslate\"><span class=\"pre\">db_collation</span></code>\nparameter to set the collation name of the column for\n<a class=\"reference internal\" href=\"/pl/6.0/ref/models/fields/#django.db.models.CharField.db_collation\" title=\"django.db.models.CharField.db_collation\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">CharField</span></code></a> and\n<a class=\"reference internal\" href=\"/pl/6.0/ref/models/fields/#django.db.models.TextField.db_collation\" title=\"django.db.models.TextField.db_collation\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">TextField</span></code></a>.</p>\n<p>The collation can also be set on a database-wide level and per-table. This is\n<a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/charset.html\">documented thoroughly</a> in the MySQL documentation. In such cases, you must\nset the collation by directly manipulating the database settings or tables.\nDjango doesn’t provide an API to change them.</p>\n<p>By default, with a UTF-8 database, MySQL will use the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">utf8mb4_0900_ai_ci</span></code> collation. This results in all string equality\ncomparisons being done in a <em>case-insensitive</em> manner. That is, <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;Fred&quot;</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;freD&quot;</span></code> are considered equal at the database level. If you have a unique\nconstraint on a field, it would be illegal to try to insert both <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;aa&quot;</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;AA&quot;</span></code> into the same column, since they compare as equal (and, hence,\nnon-unique) with the default collation. If you want case-sensitive comparisons\non a particular column or table, change the column or table to use the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">utf8mb4_0900_as_cs</span></code> collation.</p>\n<p>Please note that according to <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/charset-unicode-sets.html\">MySQL Unicode Character Sets</a>, comparisons for\nthe <code class=\"docutils literal notranslate\"><span class=\"pre\">utf8mb4_general_ci</span></code> collation are faster, but slightly less correct,\nthan comparisons for <code class=\"docutils literal notranslate\"><span class=\"pre\">utf8mb4_unicode_ci</span></code>. If this is acceptable for your\napplication, you should use <code class=\"docutils literal notranslate\"><span class=\"pre\">utf8mb4_general_ci</span></code> because it is faster. If\nthis is not acceptable (for example, if you require German dictionary order),\nuse <code class=\"docutils literal notranslate\"><span class=\"pre\">utf8mb4_unicode_ci</span></code> because it is more accurate.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Ostrzeżenie</p>\n<p>Model formsets validate unique fields in a case-sensitive manner. Thus when\nusing a case-insensitive collation, a formset with unique field values that\ndiffer only by case will pass validation, but upon calling <code class=\"docutils literal notranslate\"><span class=\"pre\">save()</span></code>, an\n<code class=\"docutils literal notranslate\"><span class=\"pre\">IntegrityError</span></code> will be raised.</p>\n</aside>\n</section>\n</section>\n<section id=\"connecting-to-the-database\">\n<h3>Connecting to the database<a class=\"heading-anchor\" href=\"#connecting-to-the-database\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Refer to the <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/\"><span class=\"doc\">settings documentation</span></a>.</p>\n<p>Connection settings are used in this order:</p>\n<ol class=\"arabic simple\">\n<li><p><a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a>.</p></li>\n<li><p><a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-NAME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">NAME</span></code></a>, <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-USER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USER</span></code></a>, <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-PASSWORD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PASSWORD</span></code></a>, <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">HOST</span></code></a>,\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-PORT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PORT</span></code></a></p></li>\n<li><p>MySQL option files.</p></li>\n</ol>\n<p>In other words, if you set the name of the database in <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a>,\nthis will take precedence over <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-NAME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">NAME</span></code></a>, which would override\nanything in a <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/option-files.html\">MySQL option file</a>.</p>\n<p>Here’s a sample configuration which uses a MySQL option file:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"c1\"># settings.py</span>\n<span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.mysql&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;read_default_file&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;/path/to/my.cnf&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<div class=\"code-block\" data-language=\"ini\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Ini</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Ini code\"><code><span class=\"c1\"># my.cnf</span>\n<span class=\"k\">[client]</span>\n<span class=\"na\">database</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s\">NAME</span>\n<span class=\"na\">user</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s\">USER</span>\n<span class=\"na\">password</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s\">PASSWORD</span>\n<span class=\"na\">default-character-set</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s\">utf8mb4</span>\n</code></pre></div>\n<p>Several other <a class=\"reference external\" href=\"https://mysqlclient.readthedocs.io/user_guide.html#functions-and-attributes\">MySQLdb connection options</a> may be useful, such as <code class=\"docutils literal notranslate\"><span class=\"pre\">ssl</span></code>,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">init_command</span></code>, and <code class=\"docutils literal notranslate\"><span class=\"pre\">sql_mode</span></code>.</p>\n<section id=\"setting-sql-mode\">\n<span id=\"mysql-sql-mode\"></span><h4>Setting <code class=\"docutils literal notranslate\"><span class=\"pre\">sql_mode</span></code><a class=\"heading-anchor\" href=\"#setting-sql-mode\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The default value of the <code class=\"docutils literal notranslate\"><span class=\"pre\">sql_mode</span></code> option contains <code class=\"docutils literal notranslate\"><span class=\"pre\">STRICT_TRANS_TABLES</span></code>.\nThat option escalates warnings into errors when data are truncated upon\ninsertion, so Django highly recommends activating a <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/sql-mode.html#sql-mode-strict\">strict mode</a> for MySQL to\nprevent data loss (either <code class=\"docutils literal notranslate\"><span class=\"pre\">STRICT_TRANS_TABLES</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">STRICT_ALL_TABLES</span></code>).</p>\n<p>If you need to customize the SQL mode, you can set the <code class=\"docutils literal notranslate\"><span class=\"pre\">sql_mode</span></code> variable\nlike other MySQL options: either in a config file or with the entry\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'init_command':</span> <span class=\"pre\">&quot;SET</span> <span class=\"pre\">sql_mode='STRICT_TRANS_TABLES'&quot;</span></code> in the\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> part of your database configuration in <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a>.</p>\n</section>\n<section id=\"mysql-isolation-level\">\n<span id=\"id9\"></span><h4>Isolation level<a class=\"heading-anchor\" href=\"#mysql-isolation-level\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>When running concurrent loads, database transactions from different sessions\n(say, separate threads handling different requests) may interact with each\nother. These interactions are affected by each session’s <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/innodb-transaction-isolation-levels.html\">transaction isolation\nlevel</a>. You can set a connection’s isolation level with an\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'isolation_level'</span></code> entry in the <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> part of your database\nconfiguration in <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a>. Valid values for\nthis entry are the four standard isolation levels:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'read</span> <span class=\"pre\">uncommitted'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'read</span> <span class=\"pre\">committed'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'repeatable</span> <span class=\"pre\">read'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'serializable'</span></code></p></li>\n</ul>\n<p>or <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> to use the server’s configured isolation level. However, Django\nworks best with and defaults to read committed rather than MySQL’s default,\nrepeatable read. Data loss is possible with repeatable read. In particular,\nyou may see cases where <a class=\"reference internal\" href=\"/pl/6.0/ref/models/querysets/#django.db.models.query.QuerySet.get_or_create\" title=\"django.db.models.query.QuerySet.get_or_create\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_or_create()</span></code></a>\nwill raise an <a class=\"reference internal\" href=\"/pl/6.0/ref/exceptions/#django.db.IntegrityError\" title=\"django.db.IntegrityError\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">IntegrityError</span></code></a> but the object won’t appear in\na subsequent <a class=\"reference internal\" href=\"/pl/6.0/ref/models/querysets/#django.db.models.query.QuerySet.get\" title=\"django.db.models.query.QuerySet.get\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get()</span></code></a> call.</p>\n</section>\n</section>\n<section id=\"creating-your-tables\">\n<h3>Creating your tables<a class=\"heading-anchor\" href=\"#creating-your-tables\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>When Django generates the schema, it doesn’t specify a storage engine, so\ntables will be created with whatever default storage engine your database\nserver is configured for. The easiest solution is to set your database server’s\ndefault storage engine to the desired engine.</p>\n<p>If you’re using a hosting service and can’t change your server’s default\nstorage engine, you have a couple of options.</p>\n<ul>\n<li><p>After the tables are created, execute an <code class=\"docutils literal notranslate\"><span class=\"pre\">ALTER</span> <span class=\"pre\">TABLE</span></code> statement to\nconvert a table to a new storage engine (such as InnoDB):</p>\n<div class=\"code-block\" data-language=\"sql\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">SQL</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"SQL code\"><code><span class=\"k\">ALTER</span><span class=\"w\"> </span><span class=\"k\">TABLE</span><span class=\"w\"> </span><span class=\"o\">&lt;</span><span class=\"n\">tablename</span><span class=\"o\">&gt;</span><span class=\"w\"> </span><span class=\"n\">ENGINE</span><span class=\"o\">=</span><span class=\"n\">INNODB</span><span class=\"p\">;</span>\n</code></pre></div>\n<p>This can be tedious if you have a lot of tables.</p>\n</li>\n<li><p>Another option is to use the <code class=\"docutils literal notranslate\"><span class=\"pre\">init_command</span></code> option for MySQLdb prior to\ncreating your tables:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;init_command&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;SET default_storage_engine=INNODB&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>This sets the default storage engine upon connecting to the database.\nAfter your tables have been created, you should remove this option as it\nadds a query that is only needed during table creation to each database\nconnection.</p>\n</li>\n</ul>\n</section>\n<section id=\"table-names\">\n<h3>Table names<a class=\"heading-anchor\" href=\"#table-names\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>There are <a class=\"reference external\" href=\"https://bugs.mysql.com/bug.php?id=48875\">known issues</a> in even the latest versions of MySQL that can cause\nthe case of a table name to be altered when certain SQL statements are executed\nunder certain conditions. It is recommended that you use lowercase table\nnames, if possible, to avoid any problems that might arise from this behavior.\nDjango uses lowercase table names when it auto-generates table names from\nmodels, so this is mainly a consideration if you are overriding the table name\nvia the <a class=\"reference internal\" href=\"/pl/6.0/ref/models/options/#django.db.models.Options.db_table\" title=\"django.db.models.Options.db_table\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">db_table</span></code></a> parameter.</p>\n</section>\n<section id=\"savepoints\">\n<h3>Savepoints<a class=\"heading-anchor\" href=\"#savepoints\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Both the Django ORM and MySQL (when using the InnoDB <a class=\"reference internal\" href=\"#mysql-storage-engines\"><span class=\"std std-ref\">storage engine</span></a>) support database <a class=\"reference internal\" href=\"/pl/6.0/topics/db/transactions/#topics-db-transactions-savepoints\"><span class=\"std std-ref\">savepoints</span></a>.</p>\n<p>If you use the MyISAM storage engine please be aware of the fact that you will\nreceive database-generated errors if you try to use the <a class=\"reference internal\" href=\"/pl/6.0/topics/db/transactions/#topics-db-transactions-savepoints\"><span class=\"std std-ref\">savepoint-related\nmethods of the transactions API</span></a>. The\nreason for this is that detecting the storage engine of a MySQL database/table\nis an expensive operation so it was decided it isn’t worth to dynamically\nconvert these methods in no-op’s based in the results of such detection.</p>\n</section>\n<section id=\"notes-on-specific-fields\">\n<h3>Notes on specific fields<a class=\"heading-anchor\" href=\"#notes-on-specific-fields\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"character-fields\">\n<span id=\"mysql-character-fields\"></span><h4>Character fields<a class=\"heading-anchor\" href=\"#character-fields\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Any fields that are stored with <code class=\"docutils literal notranslate\"><span class=\"pre\">VARCHAR</span></code> column types may have their\n<code class=\"docutils literal notranslate\"><span class=\"pre\">max_length</span></code> restricted to 255 characters if you are using <code class=\"docutils literal notranslate\"><span class=\"pre\">unique=True</span></code>\nfor the field. This affects <a class=\"reference internal\" href=\"/pl/6.0/ref/models/fields/#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CharField</span></code></a>,\n<a class=\"reference internal\" href=\"/pl/6.0/ref/models/fields/#django.db.models.SlugField\" title=\"django.db.models.SlugField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SlugField</span></code></a>. See <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/create-index.html#create-index-column-prefixes\">the MySQL documentation</a> for more\ndetails.</p>\n</section>\n<section id=\"textfield-limitations\">\n<h4><code class=\"docutils literal notranslate\"><span class=\"pre\">TextField</span></code> limitations<a class=\"heading-anchor\" href=\"#textfield-limitations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>MySQL can index only the first N chars of a <code class=\"docutils literal notranslate\"><span class=\"pre\">BLOB</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">TEXT</span></code> column. Since\n<code class=\"docutils literal notranslate\"><span class=\"pre\">TextField</span></code> doesn’t have a defined length, you can’t mark it as\n<code class=\"docutils literal notranslate\"><span class=\"pre\">unique=True</span></code>. MySQL will report: „BLOB/TEXT column «&lt;db_column&gt;» used in key\nspecification without a key length”.</p>\n</section>\n<section id=\"fractional-seconds-support-for-time-and-datetime-fields\">\n<span id=\"mysql-fractional-seconds\"></span><h4>Fractional seconds support for Time and DateTime fields<a class=\"heading-anchor\" href=\"#fractional-seconds-support-for-time-and-datetime-fields\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>MySQL can store fractional seconds, provided that the column definition\nincludes a fractional indication (e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">DATETIME(6)</span></code>).</p>\n<p>Django will not upgrade existing columns to include fractional seconds if the\ndatabase server supports it. If you want to enable them on an existing\ndatabase, it’s up to you to either manually update the column on the target\ndatabase, by executing a command like:</p>\n<div class=\"code-block\" data-language=\"sql\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">SQL</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"SQL code\"><code><span class=\"k\">ALTER</span><span class=\"w\"> </span><span class=\"k\">TABLE</span><span class=\"w\"> </span><span class=\"o\">`</span><span class=\"n\">your_table</span><span class=\"o\">`</span><span class=\"w\"> </span><span class=\"k\">MODIFY</span><span class=\"w\"> </span><span class=\"o\">`</span><span class=\"n\">your_datetime_column</span><span class=\"o\">`</span><span class=\"w\"> </span><span class=\"n\">DATETIME</span><span class=\"p\">(</span><span class=\"mi\">6</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>or using a <a class=\"reference internal\" href=\"/pl/6.0/ref/migration-operations/#django.db.migrations.operations.RunSQL\" title=\"django.db.migrations.operations.RunSQL\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RunSQL</span></code></a> operation in a\n<a class=\"reference internal\" href=\"/pl/6.0/topics/migrations/#data-migrations\"><span class=\"std std-ref\">data migration</span></a>.</p>\n</section>\n<section id=\"timestamp-columns\">\n<h4><code class=\"docutils literal notranslate\"><span class=\"pre\">TIMESTAMP</span></code> columns<a class=\"heading-anchor\" href=\"#timestamp-columns\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>If you are using a legacy database that contains <code class=\"docutils literal notranslate\"><span class=\"pre\">TIMESTAMP</span></code> columns, you\nmust set <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-USE_TZ\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_TZ</span> <span class=\"pre\">=</span> <span class=\"pre\">False</span></code></a> to avoid data corruption.\n<a class=\"reference internal\" href=\"/pl/6.0/ref/django-admin/#django-admin-inspectdb\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">inspectdb</span></code></a> maps these columns to\n<a class=\"reference internal\" href=\"/pl/6.0/ref/models/fields/#django.db.models.DateTimeField\" title=\"django.db.models.DateTimeField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">DateTimeField</span></code></a> and if you enable timezone support,\nboth MySQL and Django will attempt to convert the values from UTC to local\ntime.</p>\n</section>\n</section>\n<section id=\"row-locking-with-queryset-select-for-update\">\n<h3>Row locking with <code class=\"docutils literal notranslate\"><span class=\"pre\">QuerySet.select_for_update()</span></code><a class=\"heading-anchor\" href=\"#row-locking-with-queryset-select-for-update\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>MySQL and MariaDB do not support some options to the <code class=\"docutils literal notranslate\"><span class=\"pre\">SELECT</span> <span class=\"pre\">...</span> <span class=\"pre\">FOR</span> <span class=\"pre\">UPDATE</span></code>\nstatement. If <code class=\"docutils literal notranslate\"><span class=\"pre\">select_for_update()</span></code> is used with an unsupported option, then\na <a class=\"reference internal\" href=\"/pl/6.0/ref/exceptions/#django.db.NotSupportedError\" title=\"django.db.NotSupportedError\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">NotSupportedError</span></code></a> is raised.</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Option</p></th>\n<th class=\"head\"><p>MariaDB</p></th>\n<th class=\"head\"><p>MySQL</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">SKIP</span> <span class=\"pre\">LOCKED</span></code></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">NOWAIT</span></code></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">OF</span></code></p></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">NO</span> <span class=\"pre\">KEY</span></code></p></td>\n<td></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>When using <code class=\"docutils literal notranslate\"><span class=\"pre\">select_for_update()</span></code> on MySQL, make sure you filter a queryset\nagainst at least a set of fields contained in unique constraints or only\nagainst fields covered by indexes. Otherwise, an exclusive write lock will be\nacquired over the full table for the duration of the transaction.</p>\n</section>\n<section id=\"automatic-typecasting-can-cause-unexpected-results\">\n<h3>Automatic typecasting can cause unexpected results<a class=\"heading-anchor\" href=\"#automatic-typecasting-can-cause-unexpected-results\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>When performing a query on a string type, but with an integer value, MySQL will\ncoerce the types of all values in the table to an integer before performing the\ncomparison. If your table contains the values <code class=\"docutils literal notranslate\"><span class=\"pre\">'abc'</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">'def'</span></code> and you\nquery for <code class=\"docutils literal notranslate\"><span class=\"pre\">WHERE</span> <span class=\"pre\">mycolumn=0</span></code>, both rows will match. Similarly, <code class=\"docutils literal notranslate\"><span class=\"pre\">WHERE</span>\n<span class=\"pre\">mycolumn=1</span></code> will match the value <code class=\"docutils literal notranslate\"><span class=\"pre\">'abc1'</span></code>. Therefore, string type fields\nincluded in Django will always cast the value to a string before using it in a\nquery.</p>\n<p>If you implement custom model fields that inherit from\n<a class=\"reference internal\" href=\"/pl/6.0/ref/models/fields/#django.db.models.Field\" title=\"django.db.models.Field\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Field</span></code></a> directly, are overriding\n<a class=\"reference internal\" href=\"/pl/6.0/ref/models/fields/#django.db.models.Field.get_prep_value\" title=\"django.db.models.Field.get_prep_value\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_prep_value()</span></code></a>, or use\n<a class=\"reference internal\" href=\"/pl/6.0/ref/models/expressions/#django.db.models.expressions.RawSQL\" title=\"django.db.models.expressions.RawSQL\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RawSQL</span></code></a>,\n<a class=\"reference internal\" href=\"/pl/6.0/ref/models/querysets/#django.db.models.query.QuerySet.extra\" title=\"django.db.models.query.QuerySet.extra\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">extra()</span></code></a>, or\n<a class=\"reference internal\" href=\"/pl/6.0/topics/db/sql/#django.db.models.Manager.raw\" title=\"django.db.models.Manager.raw\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">raw()</span></code></a>, you should ensure that you perform\nappropriate typecasting.</p>\n</section>\n</section>\n<section id=\"sqlite-notes\">\n<span id=\"id10\"></span><h2>SQLite notes<a class=\"heading-anchor\" href=\"#sqlite-notes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django supports SQLite 3.31.0 and later.</p>\n<p><a class=\"reference external\" href=\"https://www.sqlite.org/\">SQLite</a> provides an excellent development alternative for applications that\nare predominantly read-only or require a smaller installation footprint. As\nwith all database servers, though, there are some differences that are\nspecific to SQLite that you should be aware of.</p>\n<section id=\"substring-matching-and-case-sensitivity\">\n<span id=\"sqlite-string-matching\"></span><h3>Substring matching and case sensitivity<a class=\"heading-anchor\" href=\"#substring-matching-and-case-sensitivity\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>For all SQLite versions, there is some slightly counterintuitive behavior when\nattempting to match some types of strings. These are triggered when using the\n<a class=\"reference internal\" href=\"/pl/6.0/ref/models/querysets/#std-fieldlookup-iexact\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">iexact</span></code></a> or <a class=\"reference internal\" href=\"/pl/6.0/ref/models/querysets/#std-fieldlookup-contains\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">contains</span></code></a> filters in querysets. The behavior\nsplits into two cases:</p>\n<p>1. For substring matching, all matches are done case-insensitively. That is a\nfilter such as <code class=\"docutils literal notranslate\"><span class=\"pre\">filter(name__contains=&quot;aa&quot;)</span></code> will match a name of <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;Aabb&quot;</span></code>.</p>\n<p>2. For strings containing characters outside the ASCII range, all exact string\nmatches are performed case-sensitively, even when the case-insensitive options\nare passed into the query. So the <a class=\"reference internal\" href=\"/pl/6.0/ref/models/querysets/#std-fieldlookup-iexact\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">iexact</span></code></a> filter will behave exactly\nthe same as the <a class=\"reference internal\" href=\"/pl/6.0/ref/models/querysets/#std-fieldlookup-exact\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">exact</span></code></a> filter in these cases.</p>\n<p>Some possible workarounds for this are <a class=\"reference external\" href=\"https://www.sqlite.org/faq.html#q18\">documented at sqlite.org</a>, but they\naren’t utilized by the default SQLite backend in Django, as incorporating them\nwould be fairly difficult to do robustly. Thus, Django exposes the default\nSQLite behavior and you should be aware of this when doing case-insensitive or\nsubstring filtering.</p>\n</section>\n<section id=\"decimal-handling\">\n<span id=\"sqlite-decimal-handling\"></span><h3>Decimal handling<a class=\"heading-anchor\" href=\"#decimal-handling\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>SQLite has no real decimal internal type. Decimal values are internally\nconverted to the <code class=\"docutils literal notranslate\"><span class=\"pre\">REAL</span></code> data type (8-byte IEEE floating point number), as\nexplained in the <a class=\"reference external\" href=\"https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes\">SQLite datatypes documentation</a>, so they don’t support\ncorrectly-rounded decimal floating point arithmetic.</p>\n</section>\n<section id=\"database-is-locked-errors\">\n<h3>„Database is locked” errors<a class=\"heading-anchor\" href=\"#database-is-locked-errors\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>SQLite is meant to be a lightweight database, and thus can’t support a high\nlevel of concurrency. <code class=\"docutils literal notranslate\"><span class=\"pre\">OperationalError:</span> <span class=\"pre\">database</span> <span class=\"pre\">is</span> <span class=\"pre\">locked</span></code> errors indicate\nthat your application is experiencing more concurrency than <code class=\"docutils literal notranslate\"><span class=\"pre\">sqlite</span></code> can\nhandle in default configuration. This error means that one thread or process\nhas an exclusive lock on the database connection and another thread timed out\nwaiting for the lock the be released.</p>\n<p>Python’s SQLite wrapper has a default timeout value that determines how long\nthe second thread is allowed to wait on the lock before it times out and raises\nthe <code class=\"docutils literal notranslate\"><span class=\"pre\">OperationalError:</span> <span class=\"pre\">database</span> <span class=\"pre\">is</span> <span class=\"pre\">locked</span></code> error.</p>\n<p>If you’re getting this error, you can solve it by:</p>\n<ul>\n<li><p>Switching to another database backend. At a certain point SQLite becomes\ntoo „lite” for real-world applications, and these sorts of concurrency\nerrors indicate you’ve reached that point.</p></li>\n<li><p>Rewriting your code to reduce concurrency and ensure that database\ntransactions are short-lived.</p></li>\n<li><p>Increase the default timeout value by setting the <code class=\"docutils literal notranslate\"><span class=\"pre\">timeout</span></code> database\noption:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"s2\">&quot;timeout&quot;</span><span class=\"p\">:</span> <span class=\"mi\">20</span><span class=\"p\">,</span>\n    <span class=\"c1\"># ...</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>This will make SQLite wait a bit longer before throwing „database is locked”\nerrors; it won’t really do anything to solve them.</p>\n</li>\n</ul>\n<section id=\"transactions-behavior\">\n<span id=\"sqlite-transaction-behavior\"></span><h4>Transactions behavior<a class=\"heading-anchor\" href=\"#transactions-behavior\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>SQLite supports three transaction modes: <code class=\"docutils literal notranslate\"><span class=\"pre\">DEFERRED</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">IMMEDIATE</span></code>, and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">EXCLUSIVE</span></code>.</p>\n<p>The default is <code class=\"docutils literal notranslate\"><span class=\"pre\">DEFERRED</span></code>. If you need to use a different mode, set it in the\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> part of your database configuration in\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a>, for example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"s2\">&quot;transaction_mode&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;IMMEDIATE&quot;</span><span class=\"p\">,</span>\n    <span class=\"c1\"># ...</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>To make sure your transactions wait until <code class=\"docutils literal notranslate\"><span class=\"pre\">timeout</span></code> before raising „Database\nis Locked”, change the transaction mode to <code class=\"docutils literal notranslate\"><span class=\"pre\">IMMEDIATE</span></code>.</p>\n<p>For the best performance with <code class=\"docutils literal notranslate\"><span class=\"pre\">IMMEDIATE</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">EXCLUSIVE</span></code>, transactions\nshould be as short as possible. This might be hard to guarantee for all of your\nviews so the usage of <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASE-ATOMIC_REQUESTS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ATOMIC_REQUESTS</span></code></a> is\ndiscouraged  in this case.</p>\n<p>For more information see <a class=\"reference external\" href=\"https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions\">Transactions in SQLite</a>.</p>\n</section>\n</section>\n<section id=\"queryset-select-for-update-not-supported\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">QuerySet.select_for_update()</span></code> not supported<a class=\"heading-anchor\" href=\"#queryset-select-for-update-not-supported\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>SQLite does not support the <code class=\"docutils literal notranslate\"><span class=\"pre\">SELECT</span> <span class=\"pre\">...</span> <span class=\"pre\">FOR</span> <span class=\"pre\">UPDATE</span></code> syntax. Calling it will\nhave no effect.</p>\n</section>\n<section id=\"isolation-when-using-queryset-iterator\">\n<span id=\"sqlite-isolation\"></span><h3>Isolation when using <code class=\"docutils literal notranslate\"><span class=\"pre\">QuerySet.iterator()</span></code><a class=\"heading-anchor\" href=\"#isolation-when-using-queryset-iterator\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>There are special considerations described in <a class=\"reference external\" href=\"https://www.sqlite.org/isolation.html\">Isolation In SQLite</a> when\nmodifying a table while iterating over it using <a class=\"reference internal\" href=\"/pl/6.0/ref/models/querysets/#django.db.models.query.QuerySet.iterator\" title=\"django.db.models.query.QuerySet.iterator\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">QuerySet.iterator()</span></code></a>. If\na row is added, changed, or deleted within the loop, then that row may or may\nnot appear, or may appear twice, in subsequent results fetched from the\niterator. Your code must handle this.</p>\n</section>\n<section id=\"enabling-json1-extension-on-sqlite\">\n<span id=\"sqlite-json1\"></span><h3>Enabling JSON1 extension on SQLite<a class=\"heading-anchor\" href=\"#enabling-json1-extension-on-sqlite\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>To use <a class=\"reference internal\" href=\"/pl/6.0/ref/models/fields/#django.db.models.JSONField\" title=\"django.db.models.JSONField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">JSONField</span></code></a> on SQLite, you need to enable the\n<a class=\"reference external\" href=\"https://www.sqlite.org/json1.html\">JSON1 extension</a> on Python’s <a class=\"reference external\" href=\"https://docs.python.org/3/library/sqlite3.html#module-sqlite3\" title=\"(w Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">sqlite3</span></code></a> library. If the extension is\nnot enabled on your installation, a system error (<code class=\"docutils literal notranslate\"><span class=\"pre\">fields.E180</span></code>) will be\nraised.</p>\n<p>To enable the JSON1 extension you can follow the instruction on\n<a class=\"reference external\" href=\"https://code.djangoproject.com/wiki/JSON1Extension\">the wiki page</a>.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Informacja</p>\n<p>The JSON1 extension is enabled by default on SQLite 3.38+.</p>\n</aside>\n</section>\n<section id=\"setting-pragma-options\">\n<span id=\"sqlite-init-command\"></span><h3>Setting pragma options<a class=\"heading-anchor\" href=\"#setting-pragma-options\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><a class=\"reference external\" href=\"https://www.sqlite.org/pragma.html\">Pragma options</a> can be set upon connection by using the <code class=\"docutils literal notranslate\"><span class=\"pre\">init_command</span></code> in\nthe <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> part of your database configuration in\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a>. The example below shows how to enable extra durability of\nsynchronous writes and change the <code class=\"docutils literal notranslate\"><span class=\"pre\">cache_size</span></code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.sqlite3&quot;</span><span class=\"p\">,</span>\n        <span class=\"c1\"># ...</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;init_command&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;PRAGMA synchronous=3; PRAGMA cache_size=2000;&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"oracle-notes\">\n<span id=\"id12\"></span><h2>Oracle notes<a class=\"heading-anchor\" href=\"#oracle-notes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django supports <a class=\"reference external\" href=\"https://www.oracle.com/\">Oracle Database Server</a> versions 19c and higher. Version\n2.3.0 or higher of the <a class=\"reference external\" href=\"https://oracle.github.io/python-oracledb/\">oracledb</a> Python driver is required.</p>\n<p>In order for the <code class=\"docutils literal notranslate\"><span class=\"pre\">python</span> <span class=\"pre\">manage.py</span> <span class=\"pre\">migrate</span></code> command to work, your Oracle\ndatabase user must have privileges to run the following commands:</p>\n<ul class=\"simple\">\n<li><p>CREATE TABLE</p></li>\n<li><p>CREATE SEQUENCE</p></li>\n<li><p>CREATE PROCEDURE</p></li>\n<li><p>CREATE TRIGGER</p></li>\n</ul>\n<p>To run a project’s test suite, the user usually needs these <em>additional</em>\nprivileges:</p>\n<ul class=\"simple\">\n<li><p>CREATE USER</p></li>\n<li><p>ALTER USER</p></li>\n<li><p>DROP USER</p></li>\n<li><p>CREATE TABLESPACE</p></li>\n<li><p>DROP TABLESPACE</p></li>\n<li><p>CREATE SESSION WITH ADMIN OPTION</p></li>\n<li><p>CREATE TABLE WITH ADMIN OPTION</p></li>\n<li><p>CREATE SEQUENCE WITH ADMIN OPTION</p></li>\n<li><p>CREATE PROCEDURE WITH ADMIN OPTION</p></li>\n<li><p>CREATE TRIGGER WITH ADMIN OPTION</p></li>\n</ul>\n<p>While the <code class=\"docutils literal notranslate\"><span class=\"pre\">RESOURCE</span></code> role has the required <code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">TABLE</span></code>,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">SEQUENCE</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">PROCEDURE</span></code>, and <code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">TRIGGER</span></code> privileges,\nand a user granted <code class=\"docutils literal notranslate\"><span class=\"pre\">RESOURCE</span> <span class=\"pre\">WITH</span> <span class=\"pre\">ADMIN</span> <span class=\"pre\">OPTION</span></code> can grant <code class=\"docutils literal notranslate\"><span class=\"pre\">RESOURCE</span></code>, such\na user cannot grant the individual privileges (e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">TABLE</span></code>), and thus\n<code class=\"docutils literal notranslate\"><span class=\"pre\">RESOURCE</span> <span class=\"pre\">WITH</span> <span class=\"pre\">ADMIN</span> <span class=\"pre\">OPTION</span></code> is not usually sufficient for running tests.</p>\n<p>Some test suites also create views or materialized views; to run these, the\nuser also needs <code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">VIEW</span> <span class=\"pre\">WITH</span> <span class=\"pre\">ADMIN</span> <span class=\"pre\">OPTION</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE</span> <span class=\"pre\">MATERIALIZED</span> <span class=\"pre\">VIEW</span> <span class=\"pre\">WITH</span> <span class=\"pre\">ADMIN</span> <span class=\"pre\">OPTION</span></code> privileges. In particular, this\nis needed for Django’s own test suite.</p>\n<p>All of these privileges are included in the DBA role, which is appropriate\nfor use on a private developer’s database.</p>\n<p>The Oracle database backend uses the <code class=\"docutils literal notranslate\"><span class=\"pre\">SYS.DBMS_LOB</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">SYS.DBMS_RANDOM</span></code>\npackages, so your user will require execute permissions on it. It’s normally\naccessible to all users by default, but in case it is not, you’ll need to grant\npermissions like so:</p>\n<div class=\"code-block\" data-language=\"sql\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">SQL</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"SQL code\"><code><span class=\"k\">GRANT</span><span class=\"w\"> </span><span class=\"k\">EXECUTE</span><span class=\"w\"> </span><span class=\"k\">ON</span><span class=\"w\"> </span><span class=\"n\">SYS</span><span class=\"p\">.</span><span class=\"n\">DBMS_LOB</span><span class=\"w\"> </span><span class=\"k\">TO</span><span class=\"w\"> </span><span class=\"k\">user</span><span class=\"p\">;</span>\n<span class=\"k\">GRANT</span><span class=\"w\"> </span><span class=\"k\">EXECUTE</span><span class=\"w\"> </span><span class=\"k\">ON</span><span class=\"w\"> </span><span class=\"n\">SYS</span><span class=\"p\">.</span><span class=\"n\">DBMS_RANDOM</span><span class=\"w\"> </span><span class=\"k\">TO</span><span class=\"w\"> </span><span class=\"k\">user</span><span class=\"p\">;</span>\n</code></pre></div>\n<section id=\"id13\">\n<h3>Connecting to the database<a class=\"heading-anchor\" href=\"#id13\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>To connect using the service name of your Oracle database, your <code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code>\nfile should look something like this:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.oracle&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;NAME&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;xe&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;USER&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;a_user&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;PASSWORD&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;a_password&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;HOST&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;PORT&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>In this case, you should leave both <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">HOST</span></code></a> and <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-PORT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PORT</span></code></a> empty.\nHowever, if you don’t use a <code class=\"docutils literal notranslate\"><span class=\"pre\">tnsnames.ora</span></code> file or a similar naming method\nand want to connect using the SID („xe” in this example), then fill in both\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">HOST</span></code></a> and <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-PORT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PORT</span></code></a> like so:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.oracle&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;NAME&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;xe&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;USER&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;a_user&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;PASSWORD&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;a_password&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;HOST&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;dbprod01ned.mycompany.com&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;PORT&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1540&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>You should either supply both <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">HOST</span></code></a> and <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-PORT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PORT</span></code></a>, or leave\nboth as empty strings. Django will use a different connect descriptor depending\non that choice.</p>\n<section id=\"full-dsn-and-easy-connect\">\n<h4>Full DSN and Easy Connect<a class=\"heading-anchor\" href=\"#full-dsn-and-easy-connect\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>A Full DSN or Easy Connect string can be used in <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-NAME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">NAME</span></code></a> if both\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">HOST</span></code></a> and <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-PORT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PORT</span></code></a> are empty. This format is required when\nusing RAC or pluggable databases without <code class=\"docutils literal notranslate\"><span class=\"pre\">tnsnames.ora</span></code>, for example.</p>\n<p>Example of an Easy Connect string:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"s2\">&quot;NAME&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;localhost:1521/orclpdb1&quot;</span>\n</code></pre></div>\n<p>Example of a full DSN string:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"s2\">&quot;NAME&quot;</span><span class=\"p\">:</span> <span class=\"p\">(</span>\n    <span class=\"s2\">&quot;(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))&quot;</span>\n    <span class=\"s2\">&quot;(CONNECT_DATA=(SERVICE_NAME=orclpdb1)))&quot;</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"oracle-pool\">\n<span id=\"id14\"></span><h3>Connection pool<a class=\"heading-anchor\" href=\"#oracle-pool\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"version-note version-added\" data-version=\"5.2\">\n<p class=\"version-note-title\">New in Django 5.2</p></aside>\n<p>To use a connection pool with <a class=\"reference external\" href=\"https://oracle.github.io/python-oracledb/\">oracledb</a>, set <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;pool&quot;</span></code> to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> in the\n<a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> part of your database configuration. This uses the driver’s\n<a class=\"reference external\" href=\"https://python-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html#connection-pooling\">create_pool()</a> default values:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.oracle&quot;</span><span class=\"p\">,</span>\n        <span class=\"c1\"># ...</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;pool&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>To pass custom parameters to the driver’s <a class=\"reference external\" href=\"https://python-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html#connection-pooling\">create_pool()</a>  function, you can\nalternatively set <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;pool&quot;</span></code> to be a dict:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.oracle&quot;</span><span class=\"p\">,</span>\n        <span class=\"c1\"># ...</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;pool&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n                <span class=\"s2\">&quot;min&quot;</span><span class=\"p\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n                <span class=\"s2\">&quot;max&quot;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span>\n                <span class=\"c1\"># ...</span>\n            <span class=\"p\">}</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n</section>\n<section id=\"insert-returning-into\">\n<h3>INSERT … RETURNING INTO<a class=\"heading-anchor\" href=\"#insert-returning-into\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>By default, the Oracle backend uses a <code class=\"docutils literal notranslate\"><span class=\"pre\">RETURNING</span> <span class=\"pre\">INTO</span></code> clause to efficiently\nretrieve the value of an <code class=\"docutils literal notranslate\"><span class=\"pre\">AutoField</span></code> when inserting new rows. This behavior\nmay result in a <code class=\"docutils literal notranslate\"><span class=\"pre\">DatabaseError</span></code> in certain unusual setups, such as when\ninserting into a remote table, or into a view with an <code class=\"docutils literal notranslate\"><span class=\"pre\">INSTEAD</span> <span class=\"pre\">OF</span></code> trigger.\nThe <code class=\"docutils literal notranslate\"><span class=\"pre\">RETURNING</span> <span class=\"pre\">INTO</span></code> clause can be disabled by setting the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">use_returning_into</span></code> option of the database configuration to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;use_returning_into&quot;</span><span class=\"p\">:</span> <span class=\"kc\">False</span><span class=\"p\">,</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>In this case, the Oracle backend will use a separate <code class=\"docutils literal notranslate\"><span class=\"pre\">SELECT</span></code> query to\nretrieve <code class=\"docutils literal notranslate\"><span class=\"pre\">AutoField</span></code> values.</p>\n</section>\n<section id=\"naming-issues\">\n<h3>Naming issues<a class=\"heading-anchor\" href=\"#naming-issues\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Oracle imposes a name length limit of 30 characters. To accommodate this, the\nbackend truncates database identifiers to fit, replacing the final four\ncharacters of the truncated name with a repeatable MD5 hash value.\nAdditionally, the backend turns database identifiers to all-uppercase.</p>\n<p>To prevent these transformations (this is usually required only when dealing\nwith legacy databases or accessing tables which belong to other users), use\na quoted name as the value for <code class=\"docutils literal notranslate\"><span class=\"pre\">db_table</span></code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">LegacyModel</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Meta</span><span class=\"p\">:</span>\n        <span class=\"n\">db_table</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;&quot;name_left_in_lowercase&quot;&#39;</span>\n\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">ForeignModel</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Meta</span><span class=\"p\">:</span>\n        <span class=\"n\">db_table</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;&quot;OTHER_USER&quot;.&quot;NAME_ONLY_SEEMS_OVER_30&quot;&#39;</span>\n</code></pre></div>\n<p>Quoted names can also be used with Django’s other supported database\nbackends; except for Oracle, however, the quotes have no effect.</p>\n<p>When running <code class=\"docutils literal notranslate\"><span class=\"pre\">migrate</span></code>, an <code class=\"docutils literal notranslate\"><span class=\"pre\">ORA-06552</span></code> error may be encountered if\ncertain Oracle keywords are used as the name of a model field or the\nvalue of a <code class=\"docutils literal notranslate\"><span class=\"pre\">db_column</span></code> option. Django quotes all identifiers used\nin queries to prevent most such problems, but this error can still\noccur when an Oracle datatype is used as a column name. In\nparticular, take care to avoid using the names <code class=\"docutils literal notranslate\"><span class=\"pre\">date</span></code>,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">timestamp</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">number</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">float</span></code> as a field name.</p>\n</section>\n<section id=\"null-and-empty-strings\">\n<span id=\"oracle-null-empty-strings\"></span><h3>NULL and empty strings<a class=\"heading-anchor\" href=\"#null-and-empty-strings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django generally prefers to use the empty string (<code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code>) rather than\n<code class=\"docutils literal notranslate\"><span class=\"pre\">NULL</span></code>, but Oracle treats both identically. To get around this, the\nOracle backend ignores an explicit <code class=\"docutils literal notranslate\"><span class=\"pre\">null</span></code> option on fields that\nhave the empty string as a possible value and generates DDL as if\n<code class=\"docutils literal notranslate\"><span class=\"pre\">null=True</span></code>. When fetching from the database, it is assumed that\na <code class=\"docutils literal notranslate\"><span class=\"pre\">NULL</span></code> value in one of these fields really means the empty\nstring, and the data is silently converted to reflect this assumption.</p>\n</section>\n<section id=\"id15\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">TextField</span></code> limitations<a class=\"heading-anchor\" href=\"#id15\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The Oracle backend stores each <code class=\"docutils literal notranslate\"><span class=\"pre\">TextField</span></code> as an <code class=\"docutils literal notranslate\"><span class=\"pre\">NCLOB</span></code> column. Oracle\nimposes some limitations on the usage of such LOB columns in general:</p>\n<ul class=\"simple\">\n<li><p>LOB columns may not be used as primary keys.</p></li>\n<li><p>LOB columns may not be used in indexes.</p></li>\n<li><p>LOB columns may not be used in a <code class=\"docutils literal notranslate\"><span class=\"pre\">SELECT</span> <span class=\"pre\">DISTINCT</span></code> list. This means that\nattempting to use the <code class=\"docutils literal notranslate\"><span class=\"pre\">QuerySet.distinct</span></code> method on a model that\nincludes <code class=\"docutils literal notranslate\"><span class=\"pre\">TextField</span></code> columns will result in an <code class=\"docutils literal notranslate\"><span class=\"pre\">ORA-00932</span></code> error when\nrun against Oracle. As a workaround, use the <code class=\"docutils literal notranslate\"><span class=\"pre\">QuerySet.defer</span></code> method in\nconjunction with <code class=\"docutils literal notranslate\"><span class=\"pre\">distinct()</span></code> to prevent <code class=\"docutils literal notranslate\"><span class=\"pre\">TextField</span></code> columns from being\nincluded in the <code class=\"docutils literal notranslate\"><span class=\"pre\">SELECT</span> <span class=\"pre\">DISTINCT</span></code> list.</p></li>\n</ul>\n</section>\n</section>\n<section id=\"subclassing-the-built-in-database-backends\">\n<span id=\"subclassing-database-backends\"></span><h2>Subclassing the built-in database backends<a class=\"heading-anchor\" href=\"#subclassing-the-built-in-database-backends\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django comes with built-in database backends. You may subclass an existing\ndatabase backend to modify its behavior, features, or configuration.</p>\n<p>Consider, for example, that you need to change a single database feature.\nFirst, you have to create a new directory with a <code class=\"docutils literal notranslate\"><span class=\"pre\">base</span></code> module in it. For\nexample:</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>mysite/\n    ...\n    mydbengine/\n        __init__.py\n        base.py\n</code></pre></div>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">base.py</span></code> module must contain a class named <code class=\"docutils literal notranslate\"><span class=\"pre\">DatabaseWrapper</span></code> that\nsubclasses an existing engine from the <code class=\"docutils literal notranslate\"><span class=\"pre\">django.db.backends</span></code> module. Here’s an\nexample of subclassing the PostgreSQL engine to change a feature class\n<code class=\"docutils literal notranslate\"><span class=\"pre\">allows_group_by_selected_pks_on_model</span></code>:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">mysite/mydbengine/base.py</span></code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.db.backends.postgresql</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">base</span><span class=\"p\">,</span> <span class=\"n\">features</span>\n\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">DatabaseFeatures</span><span class=\"p\">(</span><span class=\"n\">features</span><span class=\"o\">.</span><span class=\"n\">DatabaseFeatures</span><span class=\"p\">):</span>\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">allows_group_by_selected_pks_on_model</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">model</span><span class=\"p\">):</span>\n        <span class=\"k\">return</span> <span class=\"kc\">True</span>\n\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">DatabaseWrapper</span><span class=\"p\">(</span><span class=\"n\">base</span><span class=\"o\">.</span><span class=\"n\">DatabaseWrapper</span><span class=\"p\">):</span>\n    <span class=\"n\">features_class</span> <span class=\"o\">=</span> <span class=\"n\">DatabaseFeatures</span>\n</code></pre></figure>\n<p>Finally, you must specify a <a class=\"reference internal\" href=\"/pl/6.0/ref/settings/#std-setting-DATABASE-ENGINE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASE-ENGINE</span></code></a> in your <code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code>\nfile:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;mydbengine&quot;</span><span class=\"p\">,</span>\n        <span class=\"c1\"># ...</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>You can see the current list of database engines by looking in\n<a class=\"extlink-source reference external\" href=\"https://github.com/django/django/blob/stable/6.0.x/django/db/backends\">django/db/backends</a>.</p>\n</section>\n<section id=\"using-a-3rd-party-database-backend\">\n<span id=\"third-party-notes\"></span><h2>Using a 3rd-party database backend<a class=\"heading-anchor\" href=\"#using-a-3rd-party-database-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>In addition to the officially supported databases, there are backends provided\nby 3rd parties that allow you to use other databases with Django:</p>\n<ul class=\"simple\">\n<li><p><a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/django-cockroachdb/\">CockroachDB</a></p></li>\n<li><p><a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/django-firebird/\">Firebird</a></p></li>\n<li><p><a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/django-google-spanner/\">Google Cloud Spanner</a></p></li>\n<li><p><a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/mssql-django/\">Microsoft SQL Server</a></p></li>\n<li><p><a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/django-mongodb-backend/\">MongoDB</a></p></li>\n<li><p><a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/django-snowflake/\">Snowflake</a></p></li>\n<li><p><a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/django-tidb/\">TiDB</a></p></li>\n<li><p><a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/django-yugabytedb/\">YugabyteDB</a></p></li>\n</ul>\n<p>The Django versions and ORM features supported by these unofficial backends\nvary considerably. Queries regarding the specific capabilities of these\nunofficial backends, along with any support queries, should be directed to\nthe support channels provided by each 3rd party project.</p>\n</section>","rootId":"databases","toc":[{"title":"General notes","anchor":"general-notes","children":[{"title":"Persistent connections","anchor":"persistent-connections","children":[{"title":"Connection management","anchor":"connection-management","children":[]},{"title":"Caveats","anchor":"caveats","children":[]}]},{"title":"Encoding","anchor":"encoding","children":[]}]},{"title":"PostgreSQL notes","anchor":"postgresql-notes","children":[{"title":"PostgreSQL connection settings","anchor":"postgresql-connection-settings","children":[]},{"title":"Optimizing PostgreSQL’s configuration","anchor":"optimizing-postgresql-s-configuration","children":[]},{"title":"Isolation level","anchor":"isolation-level","children":[]},{"title":"Role","anchor":"role","children":[]},{"title":"Connection pool","anchor":"connection-pool","children":[]},{"title":"Server-side parameters binding","anchor":"server-side-parameters-binding","children":[]},{"title":"Indexes for varchar and text columns","anchor":"indexes-for-varchar-and-text-columns","children":[]},{"title":"Migration operation for adding extensions","anchor":"migration-operation-for-adding-extensions","children":[]},{"title":"Server-side cursors","anchor":"server-side-cursors","children":[{"title":"Transaction pooling and server-side cursors","anchor":"transaction-pooling-and-server-side-cursors","children":[]}]},{"title":"Manually-specifying values of auto-incrementing primary keys","anchor":"manually-specifying-values-of-auto-incrementing-primary-keys","children":[]},{"title":"Test database templates","anchor":"test-database-templates","children":[]},{"title":"Speeding up test execution with non-durable settings","anchor":"speeding-up-test-execution-with-non-durable-settings","children":[]}]},{"title":"MariaDB notes","anchor":"mariadb-notes","children":[]},{"title":"MySQL notes","anchor":"mysql-notes","children":[{"title":"Version support","anchor":"version-support","children":[]},{"title":"Storage engines","anchor":"storage-engines","children":[]},{"title":"MySQL DB API Drivers","anchor":"mysql-db-api-drivers","children":[{"title":"mysqlclient","anchor":"mysqlclient","children":[]},{"title":"MySQL Connector/Python","anchor":"id8","children":[]}]},{"title":"Time zone definitions","anchor":"time-zone-definitions","children":[]},{"title":"Creating your database","anchor":"creating-your-database","children":[{"title":"Collation settings","anchor":"collation-settings","children":[]}]},{"title":"Connecting to the database","anchor":"connecting-to-the-database","children":[{"title":"Setting sql_mode","anchor":"setting-sql-mode","children":[]},{"title":"Isolation level","anchor":"mysql-isolation-level","children":[]}]},{"title":"Creating your tables","anchor":"creating-your-tables","children":[]},{"title":"Table names","anchor":"table-names","children":[]},{"title":"Savepoints","anchor":"savepoints","children":[]},{"title":"Notes on specific fields","anchor":"notes-on-specific-fields","children":[{"title":"Character fields","anchor":"character-fields","children":[]},{"title":"TextField limitations","anchor":"textfield-limitations","children":[]},{"title":"Fractional seconds support for Time and DateTime fields","anchor":"fractional-seconds-support-for-time-and-datetime-fields","children":[]},{"title":"TIMESTAMP columns","anchor":"timestamp-columns","children":[]}]},{"title":"Row locking with QuerySet.select_for_update()","anchor":"row-locking-with-queryset-select-for-update","children":[]},{"title":"Automatic typecasting can cause unexpected results","anchor":"automatic-typecasting-can-cause-unexpected-results","children":[]}]},{"title":"SQLite notes","anchor":"sqlite-notes","children":[{"title":"Substring matching and case sensitivity","anchor":"substring-matching-and-case-sensitivity","children":[]},{"title":"Decimal handling","anchor":"decimal-handling","children":[]},{"title":"„Database is locked” errors","anchor":"database-is-locked-errors","children":[{"title":"Transactions behavior","anchor":"transactions-behavior","children":[]}]},{"title":"QuerySet.select_for_update() not supported","anchor":"queryset-select-for-update-not-supported","children":[]},{"title":"Isolation when using QuerySet.iterator()","anchor":"isolation-when-using-queryset-iterator","children":[]},{"title":"Enabling JSON1 extension on SQLite","anchor":"enabling-json1-extension-on-sqlite","children":[]},{"title":"Setting pragma options","anchor":"setting-pragma-options","children":[]}]},{"title":"Oracle notes","anchor":"oracle-notes","children":[{"title":"Connecting to the database","anchor":"id13","children":[{"title":"Full DSN and Easy Connect","anchor":"full-dsn-and-easy-connect","children":[]}]},{"title":"Connection pool","anchor":"oracle-pool","children":[]},{"title":"INSERT … RETURNING INTO","anchor":"insert-returning-into","children":[]},{"title":"Naming issues","anchor":"naming-issues","children":[]},{"title":"NULL and empty strings","anchor":"null-and-empty-strings","children":[]},{"title":"TextField limitations","anchor":"id15","children":[]}]},{"title":"Subclassing the built-in database backends","anchor":"subclassing-the-built-in-database-backends","children":[]},{"title":"Using a 3rd-party database backend","anchor":"using-a-3rd-party-database-backend","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/pl/6.0/ref/"}],"prev":{"docname":"ref/csrf","title":"Cross Site Request Forgery protection","url":"/pl/6.0/ref/csrf/"},"next":{"docname":"ref/django-admin","title":"django-admin and manage.py","url":"/pl/6.0/ref/django-admin/"},"formats":{"html":"/pl/6.0/ref/databases/","markdown":"/pl/6.0/ref/databases.md","json":"/pl/6.0/ref/databases.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/ref/databases.txt","official":"https://docs.djangoproject.com/pl/6.0/ref/databases/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}