OnDeleteType Literal is missing SET DEFAULT and NO ACTION — rejects valid SQL referential actions #1839
Unanswered
mahdirajaee
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
The
OnDeleteTypetype alias insqlmodel/main.py(line 91) is defined as:The SQL standard defines 5 referential actions for
ON DELETE/ON UPDATE:CASCADESET NULLSET DEFAULTRESTRICTNO ACTIONSQLAlchemy's
ForeignKey(ondelete=...)accepts any string and its documentation explicitly lists all 5 as valid values.Impact
NO ACTIONis the default behavior in PostgreSQL and most databases. Developers who want to be explicit in their schema (common in migration-driven workflows with Alembic) cannot express this without type errors.SET DEFAULTis used when a foreign key column has aserver_defaultand the parent row is deleted. This is supported by PostgreSQL, MySQL, and SQLite.A developer hitting this gets a confusing mypy/pyright error on a perfectly valid schema definition. The only workarounds are casting to
Anyor dropping down tosa_column.Fix
One-line change.
Beta Was this translation helpful? Give feedback.
All reactions