Implementation Of Sqlite In Django

admin | September 2nd, 2015 | General

Introduction to Sqlite In Django

Django is an open-source and free web application framework that is originally written in Python. The main purpose of Django is to ease the complexities in creation of database-driven websites. It supports four database backends-Sqlite, Oracle, MySQL, and PostgreSQL. In this tutorial we will learn how Sqlite in Django works

Database Setup Of Django

Django uses Sqlite for its configuration by default. Since Sqlite is installed in Python, you do not need to install it separately for supporting your database. The database keys used are:

  • Engine: For Sqlite the engine is django.db.backends.sqlite3
  • Name: This is the name of the database. For Sqlite the database will be a file on your machine and the name will be a full absolute path. The default value that will store the file in the directory will be os.path.join (BASE_DIR,’db.sqlite3′).

Transactions and SavePoints in Django

Transactions in Django are atomic and they can be further broken into smaller transactions referred to as SavePoints. SavePoints can also be known as partial transactions. Consider that you have a transaction that needs four SQL steps to run. In such a case, you can create a SavePoint after two steps.Once this SavePoint is created, you can do a partial rollback even if the transaction fails due to failure of third and fourth steps. This will enable you to get rid of the third and the fourth steps, without compromising with the first two steps.Thus, SavePoints enables the users to split a transaction into smaller transactions in order to do partial rollback in case of transaction failure at some point.

SavePoints In Sqlite

All the Sqlite versions, after Sqlite 3.6.8, support SavePoints. However, due to a certain flaw in the design of sqlite3, these SavePoints cannot be used at a high level.In Sqlite, when autocommit is enabled, SavePoints are rendered useless.In addition, when the autocommit is disabled, sqlite3 commits transactions before the SavePoints.Thus, this bug leads to following results:

  • The low level Application Programming Interface for SavePoints can only be used inside an atomic block, i.e. inside a transaction.
  • In case the autocommit is turned off, it is not possible to use atomic().
  • Engine Name


Sqlite and Django work efficiently together in small-scale web applications that run on a single machine. In addition, no data gets lost in large transactions and no data is lost in any moderate write activities. However, when multiple servers are run or a server-based database is used, Sqlite faces troubles when it is run over a network file system.

Disclaimer : – © 2024 Sqlite Viewer is an independent provider of Sqlite products & services. Sqlite Viewer is not in affiliation with any of the third–party organizations unless it is expressed explicitly. Read More...