python
config_error
ai_generated
true
sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on mapper, SQL expression, or this Session.
ID: python/sqlalchemy-missing-session-bind
80%Fix Rate
89%Confidence
0Evidence
2025-05-16First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.4.x | active | — | — | — |
| 2.0.x | active | — | — | — |
Root Cause
会话或引擎未正确绑定到数据库,无法执行 SQL。
generic中文
会话或引擎未正确绑定到数据库,无法执行 SQL。
Workarounds
-
95% success
创建会话时绑定引擎:Session = sessionmaker(bind=engine)
-
85% success
在查询时指定 bind:session.execute(stmt, bind=engine)
Dead Ends
Common approaches that don't work:
-
80% fail
尝试使用默认会话,但未配置引擎。
-
50% fail
在会话中手动添加 bind,但可能与其他配置冲突。