title: using sqlalchemy cannot commit to database
body: <p>I'm making a video page can track played time and comment time, every time I reload the page, using <code>{{ movie.play_num }}</code> to display the played time, it's always working but it won't change the database, So I don't know how can it be right? Seems like the <code>session.commit()</code> doesn't work.
  Besides, if I put some words in the comment field and submit, a <code>waiting for response...</code> shows up and looks like the server keep waiting until timeout.</p>
  
  <p>Here's my code: </p>
  
  <pre><code>def play(id=None):
      movie = Movie.query.join(Tag).filter(
          Tag.id == Movie.tag_id,
          Movie.id == int(id)
      ).first_or_404()
      form = CommentForm()
      if "user" in session and form.validate_on_submit():
          data = form.data
          comment = Comment(
              content=data["content"],
              movie_id=movie.id,
              user_id=session["user_id"]
          )
          db.session.add(comment)
          db.session.commit() # problem here
          movie.comment_num = movie.comment_num + 1
          flash("Success", "ok")
          return redirect(url_for("home.play", id=movie.id))
      movie.play_num = movie.play_num + 1
      try:
          db.session.commit() # and problem here
      except:
          db.session.rollback()
      return render_template("home/play.html", movie=movie, form=form)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fmA0o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fmA0o.png" alt="enter image description here"></a></p>
  
  <p>see the <code>play_num</code> has changed to 1 from 0, this is the first time I reload the page, but at the second time, the page can't be open, and the console can't collect any data.An error occurred:</p>
  
  <blockquote>
    <p>This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (pymysql.err.InternalError)</p>
  </blockquote>
  
  <p>How to fix this</p>