What is SQLite?
SQLite is an embedded SQL database library that reads and writes database files within an application process. It avoids running a separate database server and is well suited to local application storage, mobile applications and many single-node workloads. Its public-domain core is free to use, while a team still needs to design file access, backup handling and the expected pattern of concurrent writes.
Who is SQLite for?
Developers needing local, embedded or straightforward single-node SQL storage
Choose the application and operating model
SQLite runs inside the application rather than through a separate database server. Its appropriate-use guide discusses local application storage and the boundary with client/server systems. Define which application owns the file, how writes are coordinated and who can recover it.
For a central service with many writers, compare the actual access pattern and operating responsibilities with PostgreSQL or MySQL. The SQLite guidance allows many readers but one writer at a time for a database file. This is a design consideration, not a throughput result from our small example.
SQLite features
The core capabilities to consider for your workflow.
- Embedded SQL database library
- Transactional single-file databases
- No separate server process
- Public-domain deliverable code
- Cross-platform application integration
Why are my SQLite foreign keys not working?
Check enforcement on the actual connection, and set it before starting a multi-statement transaction. A foreign-key declaration alone is not enough. The foreign-key guide explains the connection setting and why changing it inside an active transaction has no effect.
PRAGMA foreign_keys = ON;
PRAGMA foreign_keys;Read the returned flag; our enabled connection returned 1. Do not infer another connection’s setting from that result or assume every build has the same default.
Three checks we actually ran
On 17 October 2026, we ran Python 3.9.6 with SQLite 3.51.0 against three fresh in-memory databases. Each had a projects table containing project 1 and an empty tasks table. Task 102 referred to missing project 999. The constraint was immediate, with no custom trigger or conflict policy. Every case explicitly set enforcement, so the test does not depend on the initial default.
| Setup | Observed result | What to take from it |
|---|---|---|
| Insert with enforcement OFF, then enable it | The invalid task was accepted. Enabling enforcement left 1 existing task; foreign_key_check returned 1 violation. | Enabling future enforcement did not repair the existing orphan. |
| Start a transaction while OFF, then attempt ON | The flag remained 0 and the invalid task was accepted. Explicit ROLLBACK left 0 tasks. | The attempted setting change inside BEGIN did not enable enforcement. |
| Enable ON before BEGIN, then insert a valid and invalid task | The invalid insert raised IntegrityError. The earlier valid task remained pending until explicit ROLLBACK. | A rejected statement did not automatically remove earlier work in this transaction. |
These observations cover the supplied schema, connection settings and runtime. They are not a concurrency, performance, recovery or application certification test.
SQLite pricing
Free embedded database
The core library has no licence subscription. Optional commercial support and warranty services are separate from application development and hosting costs.
Calculate the cost of your quote →Free access & evaluation
SQLite's deliverable code is dedicated to the public domain. It runs inside the application rather than as a hosted free-plan service.
Free core software, separate operating costs
SQLite dedicates its deliverable code to the public domain. There is no core-library seat subscription in this example. Keep optional support, application development, storage and backup work separate in the budget.
SQLite is not a hosted free-plan account. A working local database does not demonstrate that a cloud host, remote sync layer or third-party support service is included.
Before you choose SQLite
A shared file is not a substitute for a network database server
Concurrent write requirements need workload-specific checks
Application code must handle file permissions, backup and database lifecycle
Handle the failed transaction deliberately
In our enabled-connection case, task 101 referred to project 1 and was inserted first. Task 102 then failed with FOREIGN KEY constraint failed. The transaction was still open with 1 earlier valid task pending. Our explicit rollback reduced the task count to 0. A new transaction committed two valid tasks, and the final foreign-key check returned no violations.
SQLite’s conflict-handling documentation distinguishes statement failure from transaction rollback. The transaction guide discusses error handling; do not generalise this one constraint failure to every database error or deferred constraint. Decide whether the application should abandon the whole unit of work, then inspect its actual connection state.
Check existing records and reproduce the results
Use PRAGMA foreign_key_check to inspect foreign-key violations. In our orphan case it reported tasks, row 102, parent projects and foreign-key index 0. Turning enforcement on left that existing row in place; a clean setting flag was not evidence of clean data.
Download the Python reproduction ↓
Download the observed JSON results ↓
Run the file with python3 sqlite-foreign-keys-demo.py. It uses Python’s standard-library sqlite3 module, creates only in-memory databases, reports its runtime versions and makes no network requests. It asserts the recorded relationships and row counts. Your Python installation can use a different SQLite version; retain its output with your evaluation.
Explore related software
SQLite FAQs
Is SQLite free for application development?
SQLite’s deliverable code is dedicated to the public domain. Optional support and the application’s hosting, development and operating costs are separate from the core library.
Does SQLite need a separate database server?
SQLite is an embedded library running in the application process. It does not require a separate database server process; file access, coordination and recovery still need an owner.
Why are my SQLite foreign key constraints ignored?
Check PRAGMA foreign_keys on the actual connection. In the supplied test, OFF accepted a task referring to a missing project; ON set before BEGIN rejected it. Confirm build support and set the connection policy explicitly.
Why does PRAGMA foreign_keys = ON not work inside a BEGIN transaction?
Changing enforcement inside an active multi-statement transaction has no effect. In our test, the flag stayed 0 after the attempted change. Enable it outside that transaction and read the resulting flag.
Does enabling SQLite foreign keys fix existing orphan rows?
Not in the supplied test. A task inserted with enforcement OFF remained after ON was set; PRAGMA foreign_key_check reported the violation. Check and resolve existing data separately.
Does a SQLite foreign key error roll back the whole transaction?
For the immediate foreign key constraint failure in our test, the insert was rejected while an earlier valid insert remained pending and the transaction stayed open. Our explicit ROLLBACK removed that earlier task. Other errors and deferred constraints need their own handling.
How does SQLite PRAGMA foreign_key_check find existing violations?
PRAGMA foreign_key_check reports foreign-key violations. In our fixture it identified tasks row 102 referencing projects; an empty result in the final valid fixture did not constitute a full database integrity or recovery test.



