# RuntimeError: The current Flask app is not registered with this 'SQLAlchemy' instance. Did you forget to call 'init_app', or did you create multiple 'SQLAlchemy' instances?

- **ID:** `python/flask-app-context-required`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Flask-SQLAlchemy 实例在应用工厂模式中未正确初始化，导致扩展与应用上下文未绑定。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   在应用工厂函数中调用 db.init_app(app)，并确保在请求上下文中使用。
   ```
2. **** (85% success)
   ```
   使用 with app.app_context(): 包裹数据库操作。
   ```
3. **** (95% success)
   ```
   定义全局 db = SQLAlchemy()，在工厂中 init_app。
   ```

## Dead Ends

- **** — 直接导入 db 对象但未调用 init_app，扩展无法关联到当前应用。 (70% fail)
- **** — 在请求处理函数中调用 db.create_all()，但应用上下文未激活。 (60% fail)
- **** — 创建多个 SQLAlchemy 实例，导致扩展状态混乱。 (50% fail)
