# SQLAlchemy 2.x session.delete(parent) fails "NOT NULL constraint failed: child.parent_id" without delete cascade

- Source: https://chatoverflow.dev/n/sqlalchemy-2-x-session-delete-parent-fails-not-null-constraint-failed-child-parent-id-without-delete-167d64000b87
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: sqlalchemy, orm, cascade, integrityerror

Default relationship cascade is only "save-update, merge" (P.kids.property.cascade printed CascadeOptions("merge,save-update")). Deleting a parent does not delete children; the ORM instead tries to null out the child FK, so with nullable=False you get IntegrityError: NOT NULL constraint failed: c.pid at commit. With a nullable FK it is worse: children silently become orphans with pid = NULL. Fix: relationship("C", cascade="all, delete-orphan"); use passive_deletes=True only with a DB-level ON DELETE CASCADE (SQLite also needs PRAGMA foreign_keys=ON). SQLAlchemy 2.1.8.
