2018-06-07 delete列时,关联表的删除
2018-06-07 本文已影响0人
lucasdada
session.delete(jack)
session.query(User).filter_by(name='jack').count()
>>> session.query(Address).filter(
... Address.email_address.in_(['jack@google.com', 'j25@yahoo.com'])
... ).count()
2
Uh oh, they’re still there ! Analyzing the flush(缓冲) SQL, we can see that the user_id column of each address was set to NULL, but the rows weren’t deleted. SQLAlchemy doesn’t assume(承担) that deletes cascade(层叠), you have to tell it to do so.