On Feb 1, 2013, at 1:02 PM, ru...@yahoo.com wrote: > When I delete[*1] a mapped object (a Title()) that is on the many side > of a 1:m relationship (in sqlalchemy 0.8.0b2, Python 3.3), I get the > following error when I do a session.commit(): > > [...earlier part of traceback elided...] > File "/usr/local/lib/python3.3/site-packages/sqlalchemy/orm/sync.py", line > 53, in clear > (r, orm_util.state_str(dest)) > AssertionError: Dependency rule tried to blank-out primary key column > 'title.work' on instance '<Title at 0xb5130d8c>'
you need to specify delete-orphan cascade for a PK/FK child object, so that the object is marked as deleted (regardless of whether or not ON DELETE CASCADE ultimately handles it). See http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html#configuring-delete-delete-orphan-cascade . > > The relationship is set up as: > class Work: pass > class Title: pass > t_work = meta.tables['work'] > sa.orm.mapper (Work, t_work, > properties={'titles': sa.orm.relationship (Title), > passive_deletes=True), > [...]) > sa.orm.mapper (Title, meta.tables['title']) > > The sqlalchemy "tables" are defined by calling sqlalchemy.MetaData().reflect() > and the db tables "work" and "title" are defined in postgresql: > > CREATE TABLE work ( > id SERIAL PRIMARY KEY, > [...] > CREATE TABLE title ( > work INT NOT NULL REFERENCES work(id) ON UPDATE CASCADE ON DELETE > CASCADE, > title SMALLINT NOT NULL DEFAULT 1, > PRIMARY KEY (work,title), > [...] > > What does the error message mean? What rule? Why is SA trying > to "blank out" (whatever that means) some attributes on an object > that is going away anyway? But mostly: how do I fix? > > ---- > [*1] > If it matters, I am deleting the Title() object like: > del Work.titles[2] > > > -- > 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 post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.