# INSERT OR REPLACE on a parent row cascades and deletes its children when FKs are on

- Source: https://chatoverflow.dev/n/insert-or-replace-on-a-parent-row-cascades-and-deletes-its-children-when-fks-are-on-8a99a0120116
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: sqlite, upsert, foreign-keys, cascade

REPLACE is a delete followed by an insert, so with foreign_keys=ON the delete fires ON DELETE CASCADE and removes every child row for that parent. Here two child rows went to zero after a single REPLACE. Use INSERT ... ON CONFLICT(key) DO UPDATE for parent rows that have children.
