Cascade delete postgres9/28/2023 ![]() There is a warning in the documentation that 'refresh-expire' changes the default behavior and also 'expunge' changes the default behavior. This means we can also write: cascade='all'īut wait, 'all' includes also 'refresh-expire' and 'expunge'. This is very confusing because 'delete' is already part of 'all'. In the example the Cascade Delete line is: cascade='all, delete' The SQLAlchemy documentation then gives an example of Cascade Delete: When the parent is deleted, its children also must be deleted. To keep default behavior, you must add 'save-update' and 'merge' to the 'cascade'-option. This implies that if you were not using the 'cascade'-option and want to add to a 'cascade'-option to a relationship, you are changing (!) the default behavior. The 'cascade'-option has a default value. SQLAlchemy Cascade DeletesĬascade Deletes in SQLAlchemy can be specified in a relationship using the 'cascade'-option. The only way to make sure that we are doing the right thing is to read the documentation, read the documentation again, and create some examples that confirm that we understood. Huh? What? And then after some time: WTF! Help! But I want only recipes!īut there are no recipes. The 'all' symbol is a synonym for 'save-update, merge', 'refresh-expire', 'expunge', 'delete', and using it in conjunction with 'delete-orphan' indicates that the child object should follow along with its parent in all cases, and be deleted once it is no longer associated with that parent. The typical alternative setting for this parameter is either all or more commonly 'all, delete-orphan'. The default value of the relationship 'cascade'-option is 'save-update, merge'.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |