python
config_error
ai_generated
true
SQLAlchemy 未绑定执行错误:无法找到在映射器、SQL 表达式或此会话上配置的绑定。
sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on mapper, SQL expression, or this Session.
ID: python/sqlalchemy-missing-session-bind
80%修复率
89%置信度
0证据数
2025-05-16首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.4.x | active | — | — | — |
| 2.0.x | active | — | — | — |
根因分析
会话或引擎未正确绑定到数据库,无法执行 SQL。
English
会话或引擎未正确绑定到数据库,无法执行 SQL。
解决方案
-
95% 成功率
创建会话时绑定引擎:Session = sessionmaker(bind=engine)
-
85% 成功率
在查询时指定 bind:session.execute(stmt, bind=engine)
无效尝试
常见但无效的做法:
-
80% 失败
尝试使用默认会话,但未配置引擎。
-
50% 失败
在会话中手动添加 bind,但可能与其他配置冲突。