Can someone help me get the big picture when it comes to configuring SQLAlchemy models, so referential integrity is ensured at all levels?
Going by the idea that referential integrity should be expressed and enforced by the DB, I have created a schema (currently in Postgresql) with all the constraints I think I need, thus giving me a database I trust will enforce referential integrity.
I then begin to build an app on top of this DB, using SQLAlchemy (0.7) in declarative mode.
Having searched and read a bit, I have learned that I can configure:
- onupdate/ondelete rules on my Column() definitions.
- cascade options on my relationship() definitions,
and that these seem to operate on the session level in SQLAlchemy. - passive_deletes and passive_updates options for my relationship() definitions.
And that all these options have defaults.
But I am left confused as to how much I actually need to do with my SQLAlchemy models, to make sure SQLAlchemy doesn't get out of sync with the DB and its constraints during a session.
What exactly am I achieving, if I configure 'onupdate' etc. on my Columns() definitions in SQLAlchemy?
And for the cascade and passive_delete/passive_update rules I can configure on a relationship(). What do I need here, and why?
Or to rephrase my question: To what extend will SQLAlchemy be aware of the constraints configured in the DB schema, and to what extend (and how) do I have to repeat them in my models?
And are the anything else I should be aware of? :)