Hello all, 

I keep hitting an assertion error, "Dependency Rule Tried To Blank Out 
Primary Key..." when trying to remove all children using an association 
object.

My situation seems very similar 
to https://groups.google.com/forum/#!topic/sqlalchemy/3g4__pFHZTs

However, based on Michaels response, it sounds like we must delete both 
objects, which I don't want to do since it is a many-many relationship. 
Below is a simple equivalent to my code:

Page(Object):
  page_id = Column(Integer, primary_key = True)
  title = Column(String)

  user_relationships = relationship(Page_to_User)

User(Object):
  user_id = Column(Integer, primary_key = True)
  name = Column(String)

Page_to_User(Object):

  page_id = Column(Integer, ForeignKey(Page.page_id), primary_key = True)
  user_id = Column(Integer, ForeignKey(User.user_id), primary_key = True)
  relationship_type = (Integer, ForeignKey(Relationship.type_id), 
primary_key = True)

  page = relationship(Page)
  user = relationship(User)



Assuming page1 object has many users tied to it, and I want to unassociate 
them all...

print page1.user_relationships # populated with stuff, works as expected
page1.user_relationships = []
session.flush() # error here

My understanding is it page1.user_relationships is populated correctly due 
to the FK set on Page_to_User Association object. Somehow, it's getting the 
'tried to blank out' error on the Page_to_User table...

In the link above, Michael's write up sounds like the cause is if I try to 
delete the Page object, which references Page_to_User, which has foreign 
key to Page. It then tries to set page_id to null on Page_to_Actor due to 
FK constraints and ultimately fails. However, I'm not trying to delete the 
Page object here - just the associations to User. The Page stays. The User 
objects also stay. They just are not linked anymore...

Can someone help explain why I still trigger this issue? I can make it go 
away setting viewonly=True on the user_relationships relationship() call, 
but I don't want it view only - I want to be able to update and work with 
those objects as usual.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to