SQLAlchemy: cascade delete

后端 未结 9 1558
星月不相逢
星月不相逢 2020-11-28 01:07

I must be missing something trivial with SQLAlchemy\'s cascade options because I cannot get a simple cascade delete to operate correctly -- if a parent element is a deleted,

9条回答
  •  情歌与酒
    2020-11-28 01:34

    I struggled with the documentation as well, but found that the docstrings themselves tend to be easier than the manual. For example, if you import relationship from sqlalchemy.orm and do help(relationship), it will give you all the options you can specify for cascade. The bullet for delete-orphan says:

    if an item of the child's type with no parent is detected, mark it for deletion.
    Note that this option prevents a pending item of the child's class from being persisted without a parent present.

    I realize your issue was more with the way the documentation for defining parent-child relationships. But it seemed that you might also be having a problem with the cascade options, because "all" includes "delete". "delete-orphan" is the only option that's not included in "all".

提交回复
热议问题