sqlalchemy.exc.ObjectNotExecutableError: Not an executable object: 'select 1'
时间: 2024-02-11 18:08:48 浏览: 61
这个错误通常是因为你尝试直接执行一个 SQL 语句字符串,而不是 SQLAlchemy 可以执行的对象。在 SQLAlchemy 中,你可以使用 `text` 函数将 SQL 语句字符串转换为可执行的对象。
你可以尝试将这段代码修改为:
```
from sqlalchemy import text
with app.app_context():
with db.engine.connect() as conn:
rs = conn.execute(text("select 1"))
print(rs.fetchone())
```
这里我们使用 `text` 函数将字符串 `"select 1"` 转换为可执行的对象,然后将其传递给 `execute` 方法执行查询。这样就可以避免 `ObjectNotExecutableError` 错误的发生。
相关问题
raise exc.ObjectNotExecutableError(statement) from err sqlalchemy.exc.ObjectNotExecutableError: Not an executable object: 'select 1'
此错误表示在执行 SQL 语句时出现了问题,具体信息为:Not an executable object: 'select 1'。该错误是由 sqlalchemy 库中的 exc.ObjectNotExecutableError 引发的。
raise exc.ObjectNotExecutableError(statement) from err sqlalchemy.exc.ObjectNotExecutableError: ...
这个错误通常是由于在尝试执行 SQL 语句时出现问题。具体来说,可能是因为你尝试执行一个不可执行的语句(例如 SELECT 语句),或者你尝试执行一个未编译的语句。这个错误通常与 SQLAlchemy 相关。如果你遇到这个问题,建议检查一下你的代码,确保你正在尝试执行一个可执行的 SQL 语句,并且这个语句已经被正确地编译了。如果问题仍然存在,可能需要进一步调查。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)