# sqlite3.OperationalError: unable to open database file

**Code:** `unable to open database` · **Category:** SQL · **Seen on:** SQL

SQLite couldn’t open or create the database file — wrong path or missing/unwritable directory.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/sql/sqlite-unable-to-open-database-file)
