python
config_error
ai_generated
true
sqlalchemy.exc.ArgumentError: asyncio 扩展需要使用异步驱动程序。'sqlite' 驱动程序不是异步的。
sqlalchemy.exc.ArgumentError: The asyncio extension requires an async driver to be used. The 'sqlite' driver is not async.
ID: python/sqlalchemy-missing-async-driver
80%修复率
86%置信度
0证据数
2024-06-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.4.x | active | — | — | — |
| 2.0.x | active | — | — | — |
根因分析
在 SQLAlchemy 的异步扩展中使用了同步数据库驱动,如 sqlite3 或 psycopg2。
English
Using SQLAlchemy's async extension with a synchronous database driver, such as sqlite3 or psycopg2.
解决方案
-
95% 成功率
Use create_async_engine with an async driver: from sqlalchemy.ext.asyncio import create_async_engine; engine = create_async_engine('postgresql+asyncpg://user:pass@localhost/db') -
90% 成功率
For SQLite, use aiosqlite: engine = create_async_engine('sqlite+aiosqlite:///foo.db')
无效尝试
常见但无效的做法:
-
90% 失败
create_engine doesn't accept an async parameter; you must use create_async_engine.
-
80% 失败
The driver must be installed separately; otherwise ImportError occurs.