I have a self referential relationship established. A person can have one a single parent (or None), and a person can have many children (or None).
So NULL is allowed as a FK:
class Person(db.Model):
id = db.Column(db.Integer, primary_key=True)
parent_id = db.Column(db.Integer, db.ForeignKey('person.id', ondelete='RESTRICT'))
parent = db.relationship('Person', remote_side=[id], back_populates='children')
children = db.relationship('Person', back_populates='parent')
However, I want to prohibit deletions of a Person if they are a parent. So I included the ondelete='RESTRICT'
clause but it has no effect. The parent_id Column is still set to NULL when the parent is deleted.
(note my SQLite connection has swicthed pragma foreign key constraints to ON)
Why does the database not throw an Error when a parent is deleted and therefore a child Column with it as their foreign key restricts this?