Hello,

I'm currently auditing a database which uses sqlalchemy 1.1.9 and 
PostgreSQL 10 with Python 3.5.

There are a few foreign keys which are set to *ON DELETE CASCADE* on the 
database but are not set as such on the ORM side.
My first thought was to simply add in the ForeignKey, a *ondelete='CASCADE'* 
but then I saw this article: 
https://docs.sqlalchemy.org/en/13/orm/cascades.html - ORM-level “delete” 
cascade vs. FOREIGN KEY level “ON DELETE” cascade.

What I don't understand is, why would I want the ORM to handle the cascade 
if it explicitly says :

> Database level ON DELETE cascade is *vastly more efficient* than that of 
> SQLAlchemy. 


Furthermore how sqlachemy cascade handles collisions with the database 
cascade if the first one uses a one-to-many schema while the other one uses 
a many-to-one ?

And finally, should I follow my first idea and simply add the 
*ondelete='CASCADE'* and expect the same behavior as before ? 

Best regards,

Marc V.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/02b34afa-4f4e-46bb-9c46-6012e19d25f8%40googlegroups.com.

Reply via email to