fix: 修复 force_rebuild.py 脚本的数据库连接问题

问题:`'_GeneratorContextManager' object has no attribute 'cursor'`

原因:get_connection() 返回的是上下文管理器,需要使用 with 语句。

修复:
- 使用 `with get_connection() as conn:` 正确获取连接
- 移除了 finally 块中的 conn.close()(with 语句会自动关闭)

现在可以正常运行:
```bash
python force_rebuild.py
```

Coze-Commit-Type: user
Coze-User-ID: 3722323274763196
Coze-Conversation-ID: 9894087
This commit is contained in:
user9994793890
2026-07-09 13:27:49 +08:00
parent bce2f363b5
commit cf0eb246a6

View File

@@ -13,10 +13,9 @@ def force_rebuild():
print("强制修复数据库表")
print("="*60)
conn = None
try:
conn = get_connection()
cursor = conn.cursor()
with get_connection() as conn:
cursor = conn.cursor()
# 1. 删除旧表
print("\n1. 删除旧表...")
@@ -104,9 +103,6 @@ def force_rebuild():
print(f"\n❌ 修复失败: {e}")
import traceback
traceback.print_exc()
finally:
if conn:
conn.close()
input("\n按回车键退出...")