title: SqlAlchemy + MySql 1205, 'Lock wait timeout exceeded; try restarting transaction'
body: <p>I am trying to delete a row from two tables User and UserRoleMapping. </p>
  
  <blockquote>
    <p>UserRoleMapping is referenced to User table using User.id => UserRoleMapping.user_id.</p>
  </blockquote>
  
  <p>I need to delete a row from both the tables using the user specific id.</p>
  
  <p>My code</p>
  
  <pre><code>session_delete_mapping = Session()
  session_delete_user= Session()
  if request.method == "POST":
      user_id = request.form['user_list']
      try :
          num_rows_deleted_map = session_delete_mapping.query(UserRoleMapping).filter(UserRoleMapping.user_id == user_id).delete()
          num_rows_deleted_user = session_delete_user.query(UserRoleMapping).filter(User.id == user_id).delete()
          session_delete_mapping.commit()
          session_delete_user.commit()
          User.query.filter(User.id == user_id).delete()
          flash("Successfully deleted !!")
      except Exception as e:
          flash("Oops something went wrong : "+ str(e))
          session_delete_mapping.rollback()
          session_delete_user.rollback()
  return render_template('index.html')
  </code></pre>
  
  <p>but my code throws an exception</p>
  
  <blockquote>
    <p>(InternalError) (1205, 'Lock wait timeout exceeded; try restarting transaction') 'DELETE FROM user_role_mapping WHERE user_role_mapping.user_id = %s' ('3',)</p>
  </blockquote>