# sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked

- **ID:** `python/flask-sqlalchemy-commit-failure`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Flask 应用尝试写入 SQLite 数据库时，数据库文件被其他进程锁定

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## Workarounds

1. **使用连接池并设置超时** (90% success)
   ```
   app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db?timeout=10'
   ```
2. **迁移到支持并发的数据库** (95% success)
   ```
   app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://user:pass@localhost/db'
   ```

## Dead Ends

- **使用并发写入而不加锁** — SQLite 不支持并发写入，会导致数据损坏 (90% fail)
- **删除数据库文件并重新创建** — 数据丢失 (80% fail)
