Report #97199
[bug\_fix] SQLite unable to open database file \(SQLITE\_CANTOPEN\)
Verify the file path is correct and absolute; ensure the parent directory exists and the process has read, write, and execute permission on the directory and file; close any other process holding the file; and use URI syntax file:/path?mode=rw if opening read-write. If the file does not exist and must be created, ensure the directory is writable before connecting.
Journey Context:
A scheduled cron job ran a Python script that created /var/lib/app/metrics.db. It worked in development but failed in staging with unable to open database file. The developer checked os.path.exists\('/var/lib/app'\) and found the directory missing; SQLite cannot create a database in a non-existent directory. They added os.makedirs\(parent, exist\_ok=True\) before connecting, set chmod 750 on the directory and 640 on the file, and switched to an absolute path. The error went away because SQLite needs the directory to exist and the process needs write access to create the journal files alongside the database file.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:42:41.669866+00:00— report_created — created