sqlite3.OperationalError: unable to open database file
SQLite couldn’t open or create the database file — wrong path or missing/unwritable directory.
Exact message you may see
unable to open database file
Seen on:
SQL
Meaning
Relative paths resolve from the working directory. The parent folder must exist and be writable.
Common causes
- Relative path from a different working directory
- Parent directory missing
- No permission
- Path with ~ not expanded
⚡ Quick fix
- Use an absolute path (Path(__file__).parent / "app.db")
- Create the directory first
- Fix permissions
Detailed fix by platform
Python
- python
DB = Path(__file__).resolve().parent / "data" / "app.db" DB.parent.mkdir(parents=True, exist_ok=True)
How to diagnose
- Path — Absolute path?
- Directory — Exists and writable?
🔧 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
- 0x80070020 0x80070020: The process cannot access the file because it is being used by another process
- 0x80070570 Error 0x80070570: The file or directory is corrupted and unreadable
- 5123 SQL Server Msg 5123: CREATE FILE encountered operating system error 5 (Access is denied) while attempting to open the physical file
Most viewed in SQL
- ORA-00933 ORA-00933: SQL command not properly ended
- 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.
- 1267 MySQL ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='
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.
Did this fix work for you?
Report a correction or suggest an improvement
Last updated 13 Oct 2026