python runtime_error ai_generated true

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: users.age

ID: python/sqlalchemy-no-such-column

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2025-01-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

The ORM model defines a column that does not exist in the database table, or the table schema is outdated.

generic

中文

ORM 模型定义了数据库中不存在的列,或表结构已过时。

Workarounds

  1. 95% success Use Alembic migrations to add the column
    alembic revision --autogenerate -m "add age column"
    alembic upgrade head
  2. 85% success Drop and recreate the table if in development
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

Dead Ends

Common approaches that don't work:

  1. Adding the column manually via raw SQL without updating the model 65% fail

    The model may still reference the old schema if not refreshed.

  2. Ignoring the error and assuming it's transient 100% fail

    The error will persist until the schema is updated.