Forums

Unable to run flask db upgrade from flask app

I am developing flask app. I am using flask-migrate for database changes. While using command flask db upgrade with mysql database on pythonanywhere.com, I am getting the following error:

(2002, "Can't connect to server on '<myusername>.mysql.pythonanywhere-services.com' (10060)")

You need to use the username that is provided on your Databases page to connect to your database.

I am correctly using the username of my database

DB_USERNAME=prrbusinessbook
DB_PASSWORD=************ (my password for the database)
DB_HOSTNAME=prrbusinessbook.mysql.pythonanywhere-services.com
DB_DATABASENAME=pms-db

SQLALCHEMY_DATABASE_URI = f'mysql+pymysql://{DB_USERNAME}:{DB_PASSWORD}@{DB_HOSTNAME}/{DB_DATABASENAME}'

I am running flask db upgrade from my local machine. Do I have to use console on pythonanywhere.com only?

If you want to connect to your PA database from outside you need to use SSH tunnelling. See this help page for more details.