One solution is to change the commit strategy; issue commits periodically during the loop.
parentlist = session.query(Parent).all() count = 0 for parent in parentlist: session.delete(parent) count += 1 if count % 100 == 0 # use whatever frequency is needed count = 0 session.commit() if count > 0: session.commit() # this gets the last group of deletes The disadvantage of this approach is that you lose the ability to rollback the entire delete process, and now must handle that problem with application design. -- Mike Conley On Fri, May 29, 2009 at 4:08 AM, Harish Vishwanath <harish.shas...@gmail.com > wrote: > Hello, > > I am running Sqlite/SQLA/Elixir on an embedded system. I have different > classes with OneToMany relationships and I have configured cascade = "all, > delete, delete-orphan" correctly on them. However, for this to work, I > should do something like : > > parentlist = session.query(Parent).all() > for parent in parentlist: > session.delete(parent) # > session.commit() > > The above chokes the system since it has limited memory. > > The statement below : > > session.query(Parent).delete(), issues DELETE FROM PARENT; > > This is memory efficient, but it doesn't delete the child objects since > Sqlite doesn't impose FK constraints. > > Is there any way to solve this problem? > > > Regards, > Harish > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---