unable to open database 🗃️ SQL

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

  1. Use an absolute path (Path(__file__).parent / "app.db")
  2. Create the directory first
  3. Fix permissions

Detailed fix by platform

Python

  1. python
    DB = Path(__file__).resolve().parent / "data" / "app.db"
    DB.parent.mkdir(parents=True, exist_ok=True)

How to diagnose

  1. Path — Absolute path?
  2. 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.