SQLALCHEMY_DATABASE_URI not set SQLALCHEMY_DATABASE_URI not set flask flask

SQLALCHEMY_DATABASE_URI not set


You probably need to put this line app.config['SQLALCHEMY_DATABASE_URI'] = "mysql..." before the SQLAlchemy(app) instanciation.

Another option is to create SQLAlchemy() without parametters, to configure URI, and finally to tell SQLAlchemy to link with your app via sqldb.init_app(app)

Note that it is what you've done in your create_app function, but you never use it ?


Like the answer above, if you use it this way, change

sqldb = SQLAlchemy(app)

to

sqldb = SQLAlchemy()


I got the same error, and it was gone after setting the FLASK_APP environment variable :

export FLASK_APP=run.py

Start the application :

flask run --host=0.0.0.0 --port=5000