-
-
Notifications
You must be signed in to change notification settings - Fork 826
Closed
Description
Description
The OnDeleteType type alias in sqlmodel/main.py (line 91) is defined as:
OnDeleteType = Literal["CASCADE", "SET NULL", "RESTRICT"]The SQL standard defines 5 referential actions for ON DELETE / ON UPDATE:
CASCADESET NULLSET DEFAULTRESTRICTNO ACTION
SQLAlchemy'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 Any or dropping down to sa_column.
Fix
OnDeleteType = Literal["CASCADE", "SET NULL", "SET DEFAULT", "RESTRICT", "NO ACTION"]One-line change.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels