python
type_error
ai_generated
true
sqlalchemy.exc.ArgumentError: Type object 'UUID' is not a valid SQLAlchemy type
ID: python/sqlalchemy-unknown-column-type
80%Fix Rate
85%Confidence
0Evidence
2024-07-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.0.x | active | — | — | — |
Root Cause
Using a Python type like uuid.UUID directly in a Column definition without a SQLAlchemy type adapter.
generic中文
在 Column 定义中直接使用 Python 类型如 uuid.UUID,而没有使用 SQLAlchemy 类型适配器。
Workarounds
-
90% success
Use sqlalchemy.dialects.postgresql.UUID for PostgreSQL: from sqlalchemy.dialects.postgresql import UUID; id = Column(UUID(as_uuid=True), primary_key=True)
-
90% success
Use sqlalchemy.types.UUID (available in SQLAlchemy 2.0): from sqlalchemy import UUID; id = Column(UUID(as_uuid=True))
Dead Ends
Common approaches that don't work:
-
100% fail
SQLAlchemy doesn't automatically map Python's uuid.UUID.
-
70% fail
ImportError occurs if not imported properly.