SQLAlchemy无法删除具有外键关系的对象

时间:2017-02-24 18:27:37

标签: python sqlalchemy

我的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)

0 个答案:

没有答案