Python sqlalchemy.exc.IntegrityError不一致
当我删除子对象时,另一个对象的子字段为空。应该是这样的。如果仅删除依赖类对象,则应删除另一个。我应该假设如果我删除父对象,它下面的所有内容都应该被删除。从属对象、子对象以及其他对象(因为它与从属对象具有ondelete级联关系,并且从属对象与父对象具有ondelete级联关系) 当我删除父对象时,错误是抛出以下消息: sqlalchemy.exc.IntegrityError:表“child”上的更新或删除违反了表“other”上的外键约束“other\u child\u id\u fkey” 详细信息:键(id)=(4)仍然从表“另一个”引用 当我删除子对象时,另一个类没有问题。为什么我会犯这个错误Python sqlalchemy.exc.IntegrityError不一致,python,sql,postgresql,sqlalchemy,psycopg2,Python,Sql,Postgresql,Sqlalchemy,Psycopg2,当我删除子对象时,另一个对象的子字段为空。应该是这样的。如果仅删除依赖类对象,则应删除另一个。我应该假设如果我删除父对象,它下面的所有内容都应该被删除。从属对象、子对象以及其他对象(因为它与从属对象具有ondelete级联关系,并且从属对象与父对象具有ondelete级联关系) 当我删除父对象时,错误是抛出以下消息: sqlalchemy.exc.IntegrityError:表“child”上的更新或删除违反了表“other”上的外键约束“other\u child\u id\u fkey”
class Parent():
id = Column(Integer ,primary_key = true)
children = relationship('Child', back_populates='parent', passive_deletes =True)
dependents = relationship('Dependent', back_populates='parent', passive_deletes =True)
class Child():
id = Column(Integer , primary_key = true)
parent = relationship('Parent', back_populates='children')
parent_id = Column(Integer, ForeignKey('parent.id', ondelete='CASCADE')
anothers = relationship('Another', back_populates='child')
class Dependent():
id = Column(Integer , primary_key = true)
parent = relationship('Parent', back_populates='children')
parent_id = Column(Integer, ForeignKey('parent.id', ondelete='CASCADE')
another = relationship('Another', back_populates='dependent', uselist=False, passive_deletes = True)
class Another():
id = Column(Integer , primary_key = true)
dependent = relationship('Dependent', back_populates='anothers')
dependent_id = Column(Integer, ForeignKey('dependent.id', ondelete='CASCADE')
child = relationship('Child', back_populates='another')
child_id = Column(Integer, ForeignKey('child.id'))