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.
database table is lockedsqlite3.OperationalError: database table is lockedSQLITE_LOCKED: database table is lockeddatabase schema is locked 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
- Fetch all rows (or close the cursor) before changing the table
- Reset/finalize prepared statements
- Avoid shared-cache mode
Detailed fix by platform
Python
- 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
- Cursor — Still open?
- Statement — Finalised?
- 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:
Similar errors
Most viewed in SQL
- ORA-00933 ORA-00933: SQL command not properly ended
- readonly database sqlite3.OperationalError: attempt to write a readonly database
- pool timeout Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. All pooled connections were in use and max pool size was reached.
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 18 Nov 2026