title: SQLAlchemy throwing integrity error, "update or delete on table violates foreign key constraint"
body: <p>I am trying to set-up a cascade delete on a join relationship. However, whenever I try to delete a post in my application, I receive an error saying that, &quot;update or delete on table &quot;post&quot; violates foreign key constraint&quot; Here is a photo of the error message:</p>
  <p><a href="https://i.stack.imgur.com/Xi9tR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xi9tR.png" alt="Error Message" /></a></p>
  <p>Here is my code:</p>
  <pre class="lang-py prettyprint-override"><code>class Post(db.Model):
      &quot;&quot;&quot;Blog posts&quot;&quot;&quot;
  
      __tablename__ = &quot;posts&quot;
  
      id = db.Column(db.Integer,
                     primary_key=True,
                     autoincrement=True)
      title = db.Column(db.String(25),
                        nullable=False)
      content = db.Column(db.String(500),
                          nullable=False)
      created_at = db.Column(db.DateTime,
                             default=db.func.current_timestamp())
      user_table = db.Column(db.Integer, 
                             db.ForeignKey('users.id',
                                           ondelete='CASCADE'))
  
      tags = db.relationship('Tag', 
                              secondary=&quot;post_tags&quot;, 
                              back_populates=&quot;posts&quot;,
                              cascade=&quot;all, delete&quot;
                              )
  
  
  class Tag(db.Model):
  
      __tablename__ = &quot;tags&quot;
  
      id = db.Column(db.Integer,
                         primary_key=True,
                         autoincrement=True)
      name = db.Column(db.String,
                          unique=True)
      posts = db.relationship('Post',
                              secondary=&quot;post_tags&quot;,
                              back_populates=&quot;tags&quot;)
      
   
  
  class Post_Tag(db.Model):
  
      __tablename__ = &quot;post_tags&quot;
  
      post_id = db.Column(db.Integer,
                          db.ForeignKey('posts.id'), primary_key=True)
      
      tag_id = db.Column(db.Integer,
                          db.ForeignKey('tags.id'), primary_key=True)
  
  
  </code></pre>
  <p>Based on the documentation and other questions I've viewed, I seem to be setting this up correctly. What am I doing wrong here?</p>
  <p><strong>UPDATE</strong>
  I can delete Tags, but cannot delete Posts</p>