How to turn off UPDATE on child objects when deleting parent object

8 views
Skip to first unread message

Randy Syring

unread,
Sep 30, 2008, 2:14:41 AM9/30/08
to sqlalchemy
More details are here: http://groups.google.com/group/sqlelixir/browse_thread/thread/aac5d22702e3a8ec

But basically, I have a relationship between a parent (Item) table and
child (Link) table. When I try to delete an Item, an SQL statement is
generated by SQLAlchemy that tries to set Link.item_id = NULL. That
is invalid, because Link.item_id is a NOT NULL column and also because
I have a FK on the column. I have tried adjusting the cascade options
to no avail.

I would *really* appreciate some help on this, it is caused me to come
to a grinding hault on a project I am working on that needs to be done
by the end of the week.

Thanks!

Randy Syring

unread,
Sep 30, 2008, 2:17:07 AM9/30/08
to sqlalchemy
Sorry, one follow-up. I can actually get this to work by setting
cascade='all, delete-orphan'. But since the FK will do a cascading
delete, it is slower for SQLAlchemy to have to issue the statements.
Can I just make SQLAlchemy not issue anything when deleting the
parent?

On Sep 30, 2:14 am, Randy Syring <rsyr...@gmail.com> wrote:
> More details are here:http://groups.google.com/group/sqlelixir/browse_thread/thread/aac5d22...

King Simon-NFHD78

unread,
Sep 30, 2008, 5:12:17 AM9/30/08
to sqlal...@googlegroups.com

I think you need the 'passive_deletes' flag to tell SQLAlchemy that the database will delete child objects for you. It is described here:

http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_relation_largecollections_passivedelete

Hope that helps,

Simon

Randy Syring

unread,
Sep 30, 2008, 12:49:22 PM9/30/08
to sqlalchemy
Simon,

THANK YOU!! Yes, I believe that will do it.

On Sep 30, 5:12 am, "King Simon-NFHD78" <simon.k...@motorola.com>
wrote:
> http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_relatio...
>
> Hope that helps,
>
> Simon
Reply all
Reply to author
Forward
0 new messages