# alembic.util.exc.CommandError: 目标数据库不是最新的。

- **ID:** `python/flask-migrate-target-database-not-up-to-date`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在数据库版本落后于最新迁移头时运行 `flask db migrate`，或手动修改了 schema。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 4.0.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Run `flask db upgrade` first, then `flask db migrate -m 'msg'` and `flask db upgrade` again.
   ```
2. **** (85% 成功率)
   ```
   If DB drifted, stamp: `flask db stamp head` after manually aligning schema, then migrate.
   ```

## 无效尝试

- **** — Loses migration history; production DB will not match. (95% 失败率)
- **** — Offline mode still requires up-to-date revision. (80% 失败率)
