title: python sqlalchemy - can't get cascade delete to work - in mssql manager
body: <p>I have this code, thats been mostly taken from the sqlalchemy site</p>
  
  <pre><code>class Order(Base):
      __tablename__ = 'order'
      id = Column(Integer, Sequence('tri_id_seq'), primary_key=True)
      text = Column(String(1024), nullable=False)
      items = relationship("Item", cascade="save-update, delete-orphan, merge, delete", backref="parent")
  
  class Item(Base):
      __tablename__ = 'item'
      id = Column(Integer, Sequence('tri_id_seq'), primary_key=True)
      text = Column(String(1024), nullable=False)
      parent_id = Column(Integer, ForeignKey('order.id'))
  </code></pre>
  
  <p>I want deletes to Order to cascade down and delete its items as well. In code:</p>
  
  <pre><code># test insert/delete - save data to mssql server
  i1 = Item(text="item one")
  i2 = Item(text="item two")
  o = Order(text="one", items=[i1, i2])
  session.add(o)
  session.commit()
  
  session.delete(o) # delete it
  # tests to make sure items/order gone ....
  session.commit()
  </code></pre>
  
  <p>This works ok. </p>
  
  <p>BUT if I try and delete an Order in MS SQL management studio. i.e.</p>
  
  <pre><code>DELETE FROM [dbo].[order] WHERE id = 1
  </code></pre>
  
  <p>I get the error
  "the DELETE statement conflicted with the REFERENCE constraint FK__item__parent_id_1D00044F" The conflict error blah blah....</p>
  
  <p>I guess theres something missing on the relationship definitions but I can't see it.</p>
  
  <p>Any help/thoughts?</p>
  
  <p>ta.</p>