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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 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')
  2. 90% 成功率
    For SQLite, use aiosqlite: engine = create_async_engine('sqlite+aiosqlite:///foo.db')

无效尝试

常见但无效的做法:

  1. 90% 失败

    create_engine doesn't accept an async parameter; you must use create_async_engine.

  2. 80% 失败

    The driver must be installed separately; otherwise ImportError occurs.