python type_error ai_generated true

sqlalchemy.exc.CompileError: Unsupported type: <class 'sqlalchemy.dialects.postgresql.JSONB'>. Cannot compile this type.

ID: python/sqlalchemy-unknown-type

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2025-02-11First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.4.x active
2.0.x active

Root Cause

使用的数据库方言不支持 JSONB 类型,或未正确导入。

generic

中文

使用的数据库方言不支持 JSONB 类型,或未正确导入。

Workarounds

  1. 90% success
    确保使用 PostgreSQL 数据库,并从 sqlalchemy.dialects.postgresql 导入 JSONB。
  2. 85% success
    对于其他数据库,使用 JSON 类型,例如:from sqlalchemy import JSON

Dead Ends

Common approaches that don't work:

  1. 60% fail

    改用 Text 类型,但丢失了 JSON 的查询能力。

  2. 80% fail

    尝试在 MySQL 中使用 JSONB,但 MySQL 不支持该类型。