iflytek/astron-agent · error · RuntimeError
Error creating table
Error message
Error creating table {table} What it means
create_db_and_tables() iterates SQLModel.metadata.sorted_tables and calls table.create(). Any exception other than OperationalError (which is treated as 'table already exists') is logged and re-raised as RuntimeError. It wraps the original exception via `from exc`, so the underlying cause (syntax, connection, permission, driver error) is in the chain.
Solutions
- Read the chained cause (`The above exception was the direct cause of...`) in the traceback — it holds the real database error; fix that first.
- Verify the DB user has CREATE privileges on the schema/database.
- Check the engine connection URL/dialect is correct for your database (e.g. mysql+pymysql://...).
- Fix invalid column/type definitions in the SQLModel classes that produce bad DDL.
Example fix
# before
except Exception as exc:
logger.error(f"Error creating table {table}: {exc}")
raise RuntimeError(f"Error creating table {table}") from exc
# after
# inspect the full chained traceback to find the real cause, e.g.:
try:
create_db_and_tables()
except RuntimeError as e:
logger.exception("root cause", exc_info=e.__cause__) Defensive patterns
Strategy: try-catch
Validate before calling
from sqlalchemy import inspect
insp = inspect(engine)
# verify connectivity and privileges before DDL
engine.connect().execute(sqlalchemy.text("SELECT 1")) Try / catch
try:
service.create_db_and_tables()
except RuntimeError as e:
logger.exception("table creation failed; root cause: %r", e.__cause__) Prevention
- Always inspect e.__cause__ — the RuntimeError message hides the real DB error.
- Grant the DB user CREATE privileges before first boot.
- Validate the connection URL/dialect early with a smoke SELECT 1 at startup.
When it happens
Trigger: SQLAlchemy raises non-OperationalError exceptions during DDL: SQLAlchemyError subclasses like ProgrammingError for bad column definitions, ArgumentError for malformed types, or driver-level IntegrityError; also failures connecting via a misconfigured engine that surface as non-OperationalError exceptions.
Common situations: Model changes producing invalid DDL for the target DB (e.g. unsupported column types); wrong dialect/driver in the connection URL; database user lacking CREATE TABLE privileges surfacing as PermissionError-style driver exceptions; corrupted SQLModel metadata after bad model edits.
Related errors
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/c70b39cd42b6af06.
Report an issue: GitHub.
Appendix: source
Thrown at core/plugin/link/domain/models/utils.py:223
table_names = inspector.get_table_names()
current_tables = ["tools_schema"]
if table_names and all(table in table_names for table in current_tables):
logger.debug("Database and tables already exist")
return
logger.debug("Creating database and tables")
for table in SQLModel.metadata.sorted_tables:
try:
table.create(self.engine, checkfirst=True)
except OperationalError as oe:
logger.warning(
f"Table {table} already exists, skipping. Exception: {oe}"
)
except Exception as exc:
logger.error(f"Error creating table {table}: {exc}")
raise RuntimeError(f"Error creating table {table}") from exc
# Now check if the required tables exist, if not, something went wrong.
inspector = inspect(self.engine)
table_names = inspector.get_table_names()
for table_name in current_tables:
if table_name not in table_names:
logger.error("Something went wrong creating the database and tables.")
logger.error("Please check your database settings.")
raise RuntimeError(
"Something went wrong creating the database and tables."
)
logger.debug("Database and tables created successfully")
class RedisService:
"""Redis service for caching operations.
View on GitHub (pinned to 5e758547a8)