sqlite3.OperationalError: unable to open database file
SQLite couldn’t open or create the database file — wrong path or missing/unwritable directory.
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 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026