Hi, I'm trying to put online my first webapp so please be patient. I have a problem with my database. It disconnects after few minutes (less than 5).
Error log:
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 391, in _revalidate_connection
"Can't reconnect until invalid "
sqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back
This is how it is configured:
from flask.ext.sqlalchemy import SQLAlchemy
SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}".format(
username="myUsername",
password="myPassword",
hostname="myUsername.mysql.pythonanywhere-services.com",
databasename="myDatabasename",
)
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_POOL_RECYCLE"] = 299
I followed the advice http://help.pythonanywhere.com/pages/UsingSQLAlchemywithMySQL/:
from sqlalchemy import create_engine
engine = create_engine('mysql+mysqldb://myUsername:myPassword@myUsername.mysql.pythonanywhere-services.com/myDatabasename', pool_recycle=280)
But in this way it doesn't load the db at all and of course I have the same error log. Should I restart the database once I changed the configuration? Any idea how to fix it?
Thanks a lot!
UPDATE I have done some tries and I realize that the db disconnects after the first query (which is a sleep query, btw) ends. All my queries into the processlist are "sleep".