python config_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-06-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.4.x active
2.0.x active

Root Cause

Using SQLAlchemy's async extension with a synchronous database driver, such as sqlite3 or psycopg2.

generic

中文

在 SQLAlchemy 的异步扩展中使用了同步数据库驱动,如 sqlite3 或 psycopg2。

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 90% fail

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

  2. 80% fail

    The driver must be installed separately; otherwise ImportError occurs.