table is locked SQL Origin: Data OSI layer 7 · Application Last updated 18 Nov 2026

SQLite: database table is locked (SQLITE_LOCKED)

A statement on the same connection (or shared cache) conflicts with another statement that still has an open cursor on that table.

Exact message you may see database table is lockedsqlite3.OperationalError: database table is lockedSQLITE_LOCKED: database table is lockeddatabase schema is locked
Seen on: SQLite Python

Meaning

Unlike "database is locked" (SQLITE_BUSY, another connection), SQLITE_LOCKED is about conflicts within one connection or shared-cache mode: you are reading a table while dropping/altering it, or finalising nothing. Finish and close open cursors first, avoid shared cache, and don't modify a table while iterating it with the same connection.

Common causes

  • Modifying a table while a SELECT cursor is still open
  • DROP TABLE/ALTER with an unfinished statement
  • Shared-cache mode conflicts
  • Unreset prepared statements
  • Multiple threads sharing one connection

⚡ Quick fix

  1. Fetch all rows (or close the cursor) before changing the table
  2. Reset/finalize prepared statements
  3. Avoid shared-cache mode

Detailed fix by platform

Python

  1. python
    rows = cur.execute("SELECT id FROM t").fetchall()   # close the read cursor first
    for (i,) in rows: conn.execute("UPDATE t SET x=1 WHERE id=?", (i,))

How to diagnose

  1. Cursor — Still open?
  2. Statement — Finalised?
  3. Shared cache — On?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

1205 — SQL Server Msg 1205: Transaction was deadlocked on lock resources and has been chosen as the deadlock victim (SQL)12051222 — SQL Server Msg 1222: Lock request time out period exceeded (SQL)1222Deadlock — Deadlock found when trying to get lock; try restarting transaction (SQL)Deadlockdisk I/O error — SQLite: disk I/O error (SQLITE_IOERR) (SQL)disk I/O errorLock wait timeout — Lock wait timeout exceeded; try restarting transaction (MySQL 1205) (SQL)Lock wait timeoutmalformed database — sqlite3.DatabaseError: database disk image is malformed (SQL)malformed databaseORA-00054 — ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired (SQL)ORA-00054SQLite FK failed — sqlite3.IntegrityError: FOREIGN KEY constraint failed (SQL)SQLite FK failedtable is …

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.