SoFunction
Updated on 2024-11-10

Introduction to the various databases that can be adapted to the Django framework for Python

Using PostgreSQL in Django

To use PostgreSQL, you need to download the psycopg development package from /r/python-pgsql/. We recommend using psycopg2 because it is newer, more actively developed, and easier to install. Note whether you are using version 1 or 2, you will need this information later.

If you are using PostgreSQL on a Windows platform, you can get a pre-compiled binary of the psycopg development kit from /r/python-pgsql/windows/.

If you're using Linux, check that your distribution's package management system provides a set of packages with names like python-psycopg2, psycopg2-python, python-postgresql.
Using SQLite 3 in Django

If you're using Python version 2.5 or higher, you're in luck: there's no requirement to install a specific database, because Python supports communicating with SQLite. Skip ahead to the next section.

If you're using Python 2.4 or earlier, you'll need SQLite 3 instead of version 2, this can be confirmed from /r/sqlite/pysqlitehttp:///r/python-sqlite/ to make sure your pysqlite version is 2.0.3 or higher.

On Windows platforms, it is possible to skip the installation of the separate SQLite binary packages as they are statically linked into the pysqlite binary development kit.

If you're using Linux, check that your distribution's package management system provides a set of packages with names like python-sqlite3, sqlite-python, pysqlite.
Using MySQL in Django

django requires MySQL 4.0 or higher. version does not support nested subqueries and some other fairly standard SQL statements.

You will also need to download and install MySQLdb from /r/python-mysql/.

If you are using Linux, check to see if your system's package manager provides packages called python-mysql,python-mysqldb,myspl-python or similar.
Using Oracle Database in Django

django requires Oracle9i or higher.

If you use Oracle, you need to install the cx_Oracle library, available from /. To use 4.3.1 or later, but avoid 5.0, this is because of bugs in this version of the driver.
Using Django without database support

As mentioned before, Django doesn't have to have a database to work. If you just use it to provide dynamic page services that don't involve a database, it will work just as well.

Nonetheless, it's important to remember:

Some of the additional tools bundled with Django must require a database, so if you choose not to use a database, you won't be able to use those features. (We'll emphasize these features throughout the book.)