Black Lives Matter. Please consider donating to Black Girls Code today.

Can't update MYSQL database in DASH callback

Hello Everyone. I am trying to update a mysql database within a Dash callback to reprice an investment portfolio. The database app resides in a separate file in my project folder; however, I’ve imported that app’s securityholdings table to reprice the nvestments on the back of price updates from an external API.

When I run the multi app from the index file it throws the below referenced error: I can update the pandas dataframe directly within the call and then replace the table but I’d prefer to follow a more pythonic approach by updating the python objects that mirror the table records. Any idea on why Dash would throw this error when there are multi apps and how to fix it. Thanks.


The below line of codes leads to the error.
reprice = securityholdings.query.filter_by(Symbol=sekurity).first()

Below is my database app. Notice track modifications is set to True to disable the alerts which normally works without any issues.

from flask_sqlalchemy import SQLAlchemy
import sqlalchemy
import pandas as pd
from sqlalchemy import Float
import dash_html_components as html
from dash.dependencies import Input, Output, State
import dash
#app = Flask(name)
app = dash.Dash(name)
app.server.config[‘SECRET_KEY’] = ‘thisissecret’
app.server.config[‘SQLALCHEMY_DATABASE_URI’] = ‘mysql://root:root@localhost/Investments1’
app.server.config[‘SQLALCHEMY_TRACK_MODIFICATIONS’] = True

db = SQLAlchemy(app.server)

class securityholdings(db.Model):
AccountNumber = db.Column(db.String(30), unique=False)
Symbol = db.Column(db.String(10), primary_key=True)
Market_Value = db.Column(db.Float(16,2))
Shares = db.Column(db.Float(16,2))
Currency = db.Column(db.String(80))
Price = db.Column(db.Float(16,2))
Accrued_Income = db.Column(db.Float(16,2))

if name==‘main’: