我的User
模型与EmailHistory
模型有关系。当我尝试查询和删除用户时,收到错误Cannot delete or update a parent row: a foreign key constraint fails
。我已经在关系中指定了cascade='all, delete-orphan'
。删除用户时如何删除相关行?
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
emails = db.relationship('EmailHistory', cascade='all, delete-orphan', backref='user', lazy='dynamic')
class EmailHistory(db.Model):
id = db.Column(db.Integer, primary_key=True)