I was trying to do something like this:
class Parent(Base):
__tablename__ = 'parents'
id = Column(Integer, primary_key=True)
class Child(Base):
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('parents.id'))
Parent = relationship('Parent', backref=backref('children', passive_deletes=True))
parent = db.session.query(Parent).filter(id=some_id).first()
print parent.children
db.session.delete(parent)
db.session.commit()
I don't want sqlalchemy to create a lot of queries for deleting children. I have foreign key constraint instead of it. But i am getting the error:
sqlalchemy.exc.IntegrityError: (IntegrityError) null value in column "parent" violates not-null constraint
It is beacause i don't use lazy='dynamic' option in relationship parameters. But i can't use the option because joinedload option would not work with lazy='dynamic' option. How can i avoid these problems?