title: Flask: Saving chat messages in database
body: <p>So I am in the midst of adding chat history to my flask website. In order to do that, I have to first save the messages and room id in a separate class. However, I am getting an error for some reason while trying to save these messages. Could someone guide me on how to save the messages without getting an error? I have put the code below. Thank you. I am trying to do this because of the solution provided to one of my other questions. So if you do not find any issues in this, please go to this <a href="https://stackoverflow.com/questions/67337584/flask-how-to-add-chat-history-depending-on-the-chat-room-in-flask/67346667#67346667">link</a> to view my question and the answer provided to get further clarity.</p>
  <p><strong>main.py</strong></p>
  <pre><code>    from flask import Flask, request, session, render_template, redirect, url_for, flash, get_flashed_messages, jsonify
      from flask.globals import current_app
      from flask_login import LoginManager, login_user, login_required, logout_user, current_user, UserMixin, AnonymousUserMixin
      from datetime import timedelta, datetime
      from werkzeug.security import generate_password_hash, check_password_hash
      import sqlite3
      from os import error, path
      from flask_sqlalchemy import SQLAlchemy
      import random
      from flask_socketio import SocketIO, join_room, leave_room, emit
      from flask_session import Session
  
      app = Flask(__name__)
      DB_NAME = &quot;spark.db&quot;
      app.config[&quot;SECRET_KEY&quot;] = &quot;1986319249872139865432&quot;
      app.config['SQLALCHEMY_DATABASE_URI'] = f&quot;sqlite:///{DB_NAME}&quot;
      app.config[&quot;SQLALCHEMY_TRACK_MODIFICATIONS&quot;] = False
      app.config['SESSION_TYPE'] = 'filesystem'
  
  
      Session(app)
  
      socketio = SocketIO(app, manage_session=False)
  
      db = SQLAlchemy(app)
      db.init_app(app)
  
      def create_database(app):
          if not path.exists(DB_NAME):
              db.create_all(app=app)
              print(&quot;Created Database!&quot;)
  
      class Tutor(db.Model, UserMixin):
          id = db.Column(db.Integer, primary_key=True)
          user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
          tremail = db.Column(db.String(10000))
          trusername = db.Column(db.String(1200))
          subjects = db.Column(db.String(1200))
          session_length = db.Column(db.String(1200))
  
      class Messages(db.Model, UserMixin):
          id = db.Column(db.Integer, primary_key=True)
          room_id = db.Column(db.String(1200), unique=True, nullable=False)
          content = db.Column(db.String(10000))
  
      class User(db.Model, UserMixin):
          id = db.Column(db.Integer, primary_key=True)
          email = db.Column(db.String(150), unique=True)
          username = db.Column(db.String(150), unique=True)
          password = db.Column(db.String(150))
          tutors = db.relationship('Tutor')
  
  
      create_database(app)
  
      login_manager = LoginManager()
      login_manager.login_view = 'login'
      login_manager.init_app(app)
      @login_manager.user_loader
      def load_user(id):
          return User.query.get(int(id))
  
  
      @app.route(&quot;/&quot;)
      @login_required
      def home():
          return render_template(&quot;index.html&quot;)
  
      @app.route(&quot;/login&quot;, methods=[&quot;GET&quot;, 'POST'])
      def login():
          if request.method == &quot;POST&quot;:
              email = request.form.get('email')
              password = request.form.get('password')
  
              user = User.query.filter_by(email=email).first()
              if user:
                  if check_password_hash(user.password, password):
                      flash('Login successful!', category=&quot;success&quot;)
                      login_user(user, remember=True)
                      return redirect(url_for(&quot;home&quot;))
                  else:
                      flash('Incorrect password! Please try again.', category=&quot;error&quot;)
              else:
                  flash(&quot;Account does not exist. Please register to continue.&quot;, category=&quot;error&quot;)
  
  
          return render_template(&quot;login.html&quot;, user=current_user)
  
      @app.route(&quot;/register&quot;, methods=[&quot;GET&quot;, &quot;POST&quot;])
      def register():
          if request.method == 'POST':
              email = request.form.get('email')
              username = request.form.get('username')
              password1 = request.form.get('password1')
              password2 = request.form.get('password2')
  
              user = User.query.filter_by(email=email).first()
              if user:
                  flash(&quot;Email already exists.&quot;, category=&quot;error&quot;)
              elif len(email) &lt; 4:
                  flash(&quot;Email must be greater than 3 characters.&quot;, category=&quot;error&quot;)
              elif len(username) &lt; 2:
                  flash(&quot;Username must be greater than 1 character.&quot;, category=&quot;error&quot;)
              elif password1 != password2:
                  flash(&quot;Passwords do not match! Please try again.&quot;, category=&quot;error&quot;)
              elif len(password1) &lt; 8:
                  flash(&quot;Password must be greater than 7 characters.&quot;, category=&quot;error&quot;)
              else:
                  new_user = User(email=email, username=username, password=generate_password_hash(password1, method='sha256'))
                  db.session.add(new_user)
                  db.session.commit()
                  login_user(new_user, remember=True)
                  flash(&quot;Account successfully created!&quot;, category=&quot;success&quot;)
  
                  return redirect(url_for('home'))
  
          return render_template(&quot;register.html&quot;, user=current_user)
  
      @app.route(&quot;/logout&quot;)
      @login_required
      def logout():
          logout_user()
          flash(&quot;Logged out succcessfully!&quot;, category=&quot;success&quot;)
          return redirect(url_for('login'))
  
      @app.route(&quot;/selection&quot;)
      @login_required
      def selection():
          return render_template(&quot;selection.html&quot;)
  
      @app.route(&quot;/tutorform&quot;, methods=['GET', 'POST'])
      @login_required
      def tutorform():
          if request.method == 'POST':
              email = request.form.get('email')
              tremail = request.form.get('tremail')
              trusername = request.form.get('trusername')
              subjects = request.form.get('subjects')
              session_length = request.form.get('session_length')
  
              new_tutor = Tutor(user_id=current_user.id, tremail=tremail, trusername=trusername, subjects=subjects, session_length=session_length)
              db.session.add(new_tutor)
              db.session.commit()
              flash('Entry has been saved!', category='success')
              return redirect(url_for(&quot;display&quot;))
  
          return render_template(&quot;tutorform.html&quot;, user=current_user)
  
      @app.route(&quot;/tutoreeform&quot;, methods=['GET', 'POST'])
      @login_required
      def tutoreeform():
          if request.method == 'POST':
              flash(&quot;Tutoree Entry Successful!&quot;, category='success')
              return redirect(url_for(&quot;display&quot;))
  
          return render_template(&quot;tutoreeform.html&quot;)
  
      @app.route(&quot;/display&quot;)
      @login_required
      def display():
          users = Tutor.query.all()
  
          return render_template(&quot;display.html&quot;, users=users)
  
      @login_required
      @app.route('/chat', methods=['GET', 'POST'])
      def chat():
          if(request.method=='POST'):
              username = current_user.username
              room = request.form['room']
              #Store the data in session
              session['username'] = username
              session['room'] = room
              return render_template('chat.html', session = session)
          else:
              if(current_user.username is not None):
                  return render_template('chat.html', session = session)
              else:
                  return redirect(url_for('chatselection'))
  
      class Anonymous(AnonymousUserMixin):
      def __init__(self):
          self.username = 'Guest'
  
      @socketio.on('join', namespace='/chat')
      @login_required
      def join(message):
          room = session.get('room')
          join_room(room)
          emit('status', {'msg': current_user.username + ' has entered the room.'}, room=room)
  
  
      @socketio.on('text', namespace='/chat')
      @login_required
      def text(message):
          room = session.get('room')
  
          message = Messages(room_id=room, content=message)
          db.session.add(message)
          db.session.commit()
          emit('message', {'msg': session.get('username') + ' : ' + message['msg']}, room=room)
  
      @socketio.on('left', namespace='/chat')
      @login_required
      def left(message):
          room = session.get('room')
          leave_room(room)
          session.clear()
          emit('status', {'msg': current_user.username + ' has left the room.'}, room=room)
  
      @app.route(&quot;/chatselection&quot;, methods=['GET', 'POST'])
      def chatselection():
          return render_template(&quot;chatselection.html&quot;)
  
  
      if __name__ == '__main__':
          db.create_all()
          socketio.run(app, debug=True)
  </code></pre>
  <p><strong>chat.html</strong></p>
  <pre><code>{% extends &quot;base.html&quot; %}
  
  {% block title %}SparkWIT | | Chat{% endblock %}
  
  {% block content %}
      &lt;div class=&quot;chatwindow&quot;&gt;
          &lt;center&gt;&lt;h2 style=&quot;color: beige;&quot;&gt;SparkWIT Babbles!&lt;/h2&gt;&lt;/center&gt;
          &lt;center&gt;&lt;h3 style=&quot;color: beige;&quot;&gt;Room : {{session['room']}}&lt;/h3&gt;&lt;/center&gt;&lt;br&gt;
          &lt;center&gt;&lt;textarea id=&quot;chat&quot; cols=&quot;90&quot; rows=&quot;12&quot; placeholder=&quot;No messages yet. Start one...&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;/center&gt;
          &lt;div&gt;
        &lt;center&gt;&lt;div class=&quot;buttonIn&quot;&gt;
          &lt;input type=&quot;text&quot; id=&quot;text&quot; name=&quot;text&quot; size=&quot;75&quot; placeholder=&quot;Enter your message here&quot; /&gt;
          &lt;button type=&quot;button&quot; id=&quot;send&quot; class=&quot;btn btn-success&quot;&gt;SEND&lt;/button&gt;
          &lt;br&gt;
          &lt;br&gt;
        &lt;/div&gt;&lt;/center&gt;
        &lt;center&gt;&lt;button type=&quot;button&quot; class=&quot;btn btn-danger&quot; onclick=leave_room()&gt;Leave this Chat&lt;/button&gt;&lt;/center&gt;
      &lt;/div&gt;
  {% endblock %}
  </code></pre>
  <p><strong>chatselection.html</strong></p>
  <pre><code>{% extends &quot;base.html&quot; %}
  {% block title %}SparkWIT | | Chat Selection{% endblock %}
  
  {% block content %}
  
  &lt;center&gt;&lt;h1 class=&quot;h2 mb-3 font-weight-normal&quot; style=&quot;color: beige;&quot;&gt;SparkWIT Babbles&lt;/h1&gt;&lt;br&gt;&lt;br&gt;&lt;/center&gt;
  &lt;br&gt;
  &lt;hr&gt;
    &lt;form class=&quot;form-signin&quot; action=&quot;{{url_for('chat')}}&quot; method=&quot;POST&quot;&gt;
      &lt;input type=&quot;text&quot; id=&quot;room&quot; name=&quot;room&quot; class=&quot;form-control&quot; placeholder=&quot;Room Code&quot; required&gt;&lt;br&gt;
      &lt;button class=&quot;btn btn-lg btn-primary btn-block&quot; value=&quot;submit&quot;&gt;Create/Join Room&lt;/button&gt;
    &lt;/form&gt;
  &lt;br&gt;
  
  
  {% endblock %}
  </code></pre>
  <p><strong>base.html</strong></p>
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
          &lt;head&gt;
              &lt;title &gt;{% block title %}{% endblock %}&lt;/title&gt;
              &lt;link rel= &quot;stylesheet&quot; type= &quot;text/css&quot; href= &quot;{{ url_for('static',filename='style.css') }}&quot;&gt;
              &lt;link rel= &quot;stylesheet&quot; type= &quot;text/css&quot; href= &quot;{{ url_for('static',filename='bootstrap.min.css') }}&quot;&gt;
              &lt;link rel=&quot;stylesheet&quot; href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css&quot; integrity=&quot;sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T&quot; crossorigin=&quot;anonymous&quot;&gt;
  
              &lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js&quot; integrity=&quot;sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
  
      &lt;!-- Bootstrap core JavaScript --&gt;
              &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js&quot;&gt;&lt;/script&gt;
  
      &lt;!-- Plugin JavaScript --&gt;
              &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js&quot;&gt;&lt;/script&gt;
              &lt;script src=&quot;https://cdn.jsdelivr.net/npm/startbootstrap-stylish-portfolio@5.0.9/js/stylish-portfolio.min.js&quot;&gt;&lt;/script&gt;
  
              &lt;script type=&quot;text/javascript&quot; src=&quot;//code.jquery.com/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
              &lt;script src=&quot;https://cdn.socket.io/3.1.3/socket.io.min.js&quot; integrity=&quot;sha384-cPwlPLvBTa3sKAgddT6krw0cJat7egBga3DJepJyrLl4Q9/5WLra3rrnMcyTyOnh&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
              &lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
                  var socket;
                  $(document).ready(function(){
                      socket = io.connect('http://' + document.domain + ':' + location.port + '/chat');
                      socket.on('connect', function() {
                          socket.emit('join', {});
                      });
                      socket.on('status', function(data) {
                          $('#chat').val($('#chat').val() + '&lt;' + data.msg + '&gt;\n');
                          $('#chat').scrollTop($('#chat')[0].scrollHeight);
                      });
                      socket.on('message', function(data) {
                          $('#chat').val($('#chat').val() + data.msg + '\n');
                          $('#chat').scrollTop($('#chat')[0].scrollHeight);
                      });
                      $('#send').click(function(e) {
                              text = $('#text').val();
                              $('#text').val('');
                              socket.emit('text', {msg: text});
                      });
                  });
                  function leave_room() {
                      socket.emit('left', {}, function() {
                          socket.disconnect();
                          // go back to the login page
                          window.location.href = &quot;{{ url_for('display') }}&quot;;
                      });
                  }
              &lt;/script&gt;
  
          &lt;/head&gt;
          &lt;body style=&quot;background-image: url(https://media.istockphoto.com/photos/abstract-glittering-dna-helix-with-depth-of-field-over-dark-space-picture-id1201193016?k=6&amp;m=1201193016&amp;s=612x612&amp;w=0&amp;h=_H80RaLa4OYIiT136j_cFgm-YRHAiV4wmaSkSKAMFbQ=)&quot;&gt;
              &lt;nav class=&quot;navbar navbar-expand-lg navbar-dark&quot; style=&quot;background-color: #549bf773;&quot;&gt;
                  &lt;a class=&quot;navbar-brand&quot; href=&quot;/&quot;&gt;
                      &lt;img src=&quot;{{url_for('static', filename='logo.jpg')}}&quot; alt=&quot;&quot; width=&quot;40&quot;&gt;
                  &lt;/a&gt;
                  &lt;a class=&quot;navbar-brand&quot; href=&quot;/&quot; style=&quot;color: rgb(22, 9, 3);&quot;&gt;&lt;i&gt;&lt;b style=&quot;font-family: fantasy; font-size: larger;&quot;&gt;SparkWIT&lt;/b&gt;&lt;/i&gt;&lt;/a&gt;
                  &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#navbarSupportedContent&quot; aria-controls=&quot;navbarSupportedContent&quot; aria-expanded=&quot;false&quot; aria-label=&quot;Toggle navigation&quot;&gt;
                  &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;
                  &lt;/button&gt;
  
                  {% if current_user.is_authenticated %}
                  &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarSupportedContent&quot;&gt;
                      &lt;ul class=&quot;navbar-nav mr-auto&quot;&gt;
                      &lt;li class=&quot;nav-item active&quot;&gt;
                          &lt;a class=&quot;nav-link&quot; href=&quot;/&quot; style=&quot;color: rgb(37, 20, 13);&quot;&gt;&lt;b&gt;&lt;i&gt;Home&lt;/i&gt;&lt;/b&gt; &lt;span class=&quot;sr-only&quot;&gt;(current)&lt;/span&gt;&lt;/a&gt;
                      &lt;/li&gt;
                      &lt;li class=&quot;nav-item active&quot;&gt;
                          &lt;a class=&quot;nav-link&quot; href=&quot;/selection&quot; style=&quot;color: rgb(37, 20, 13);&quot;&gt;&lt;b&gt;&lt;i&gt;Selection&lt;/i&gt;&lt;/b&gt; &lt;span class=&quot;sr-only&quot;&gt;(current)&lt;/span&gt;&lt;/a&gt;
                      &lt;/li&gt;
                      &lt;/ul&gt;
                      &lt;a class=&quot;nav-link&quot; href=&quot;/logout&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn btn-outline-danger&quot; style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;b&gt;Logout&lt;/b&gt;&lt;/button&gt;&lt;/a&gt;
                  {% else %}
  
                      &lt;a class=&quot;nav-link&quot; href=&quot;/login&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn btn-outline-light&quot;&gt;&lt;b&gt;Login&lt;/b&gt;&lt;/button&gt;&lt;/a&gt;
                      &lt;a class=&quot;nav-link&quot; href=&quot;/register&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn btn-outline-warning&quot;&gt;&lt;b&gt;Register&lt;/b&gt;&lt;/button&gt;&lt;/a&gt;
                  {% endif %}
                  &lt;/div&gt;
              &lt;/nav&gt;
  
                      {% with messages = get_flashed_messages(with_categories=true) %}
              {% if messages %}
                  {% for category, message in messages %}
                  {% if category == &quot;error&quot; %}
                  &lt;div class=&quot;alert alert-danger alter-dismissable fade show&quot; role=&quot;alert&quot;&gt;
                      {{ message }}
                      &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot;&gt;
                          &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                  &lt;/div&gt;
                  {% endif %}
                  {% if category == &quot;success&quot; %}
                  &lt;div class=&quot;alert alert-success alter-dismissable fade show&quot; role=&quot;alert&quot;&gt;
                      {{ message }}
                      &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot;&gt;
                          &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                  &lt;/div&gt;
                  {% endif %}
                  {% endfor %}
              {% endif %}
              {% endwith %}
  
              &lt;div class=&quot;container&quot;&gt;
                  {% block content %}{% endblock %}
              &lt;/div&gt;
              &lt;script src=&quot;https://code.jquery.com/jquery-3.3.1.slim.min.js&quot; integrity=&quot;sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
              &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js&quot; integrity=&quot;sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
              &lt;script src=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js&quot; integrity=&quot;sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  <p>This is the error I'm getting by the way.</p>
  <pre><code>    Exception in thread Thread-32:
      Traceback (most recent call last):
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py&quot;, line 1276, in _execute_context       
          self.dialect.do_execute(
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\default.py&quot;, line 593, in do_execute
          cursor.execute(statement, parameters)
      sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.
  
      The above exception was the direct cause of the following exception:
  
      Traceback (most recent call last):
      File &quot;D:\Everyday_Uses\lib\threading.py&quot;, line 954, in _bootstrap_inner
          self.run()
      File &quot;D:\Everyday_Uses\lib\threading.py&quot;, line 892, in run
          self._target(*self._args, **self._kwargs)
      File &quot;D:\Everyday_Uses\lib\site-packages\socketio\server.py&quot;, line 680, in _handle_event_internal
          r = server._trigger_event(data[0], namespace, sid, *data[1:])
      File &quot;D:\Everyday_Uses\lib\site-packages\socketio\server.py&quot;, line 704, in _trigger_event
          return self.handlers[namespace][event](*args)
      File &quot;D:\Everyday_Uses\lib\site-packages\flask_socketio\__init__.py&quot;, line 283, in _handler
          return self._handle_event(handler, message, namespace, sid,
      File &quot;D:\Everyday_Uses\lib\site-packages\flask_socketio\__init__.py&quot;, line 751, in _handle_event
          ret = handler(*args)
      File &quot;D:\Everyday_Uses\lib\site-packages\flask_login\utils.py&quot;, line 272, in decorated_view
          return func(*args, **kwargs)
      File &quot;d:\Everyday_Uses\Programming\SparkWIT\main.py&quot;, line 200, in text
          db.session.commit()
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\scoping.py&quot;, line 163, in do
          return getattr(self.registry(), name)(*args, **kwargs)
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\session.py&quot;, line 1042, in commit
          self.transaction.commit()
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\session.py&quot;, line 504, in commit
          self._prepare_impl()
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\session.py&quot;, line 483, in _prepare_impl
          self.session.flush()
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\session.py&quot;, line 2536, in flush
          self._flush(objects)
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\session.py&quot;, line 2678, in _flush
          transaction.rollback(_capture_exception=True)
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\util\langhelpers.py&quot;, line 68, in __exit__
          compat.raise_(
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\util\compat.py&quot;, line 182, in raise_
          raise exception
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\session.py&quot;, line 2638, in _flush
          flush_context.execute()
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\unitofwork.py&quot;, line 422, in execute
          rec.execute(self)
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\unitofwork.py&quot;, line 586, in execute
          persistence.save_obj(
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\persistence.py&quot;, line 239, in save_obj
          _emit_insert_statements(
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\orm\persistence.py&quot;, line 1135, in _emit_insert_statements
          result = cached_connections[connection].execute(
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py&quot;, line 1011, in execute
          return meth(self, multiparams, params)
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\sql\elements.py&quot;, line 298, in _execute_on_connection 
          return connection._execute_clauseelement(self, multiparams, params)
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py&quot;, line 1124, in _execute_clauseelement 
          ret = self._execute_context(
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py&quot;, line 1316, in _execute_context       
          self._handle_dbapi_exception(
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py&quot;, line 1510, in _handle_dbapi_exception    util.raise_(
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\util\compat.py&quot;, line 182, in raise_
          raise exception
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py&quot;, line 1276, in _execute_context
          self.dialect.do_execute(
      File &quot;C:\Users\aarya\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\default.py&quot;, line 593, in do_execute
          cursor.execute(statement, parameters)
      sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter 1 - probably unsupported type.
      [SQL: INSERT INTO messages (room_id, content) VALUES (?, ?)]
      [parameters: ('test', {'msg': 'gsefasd'})]
      (Background on this error at: http://sqlalche.me/e/13/rvf5)
  </code></pre>