I'm trying to connect my flask application to my local MySQL database for testing. I've made a flask object and a class to represent an example table to be created after a successful connection.
These are my local env vars for my project:
#.env
LOCAL_MYSQL_URL = mysql://Username:somePassword@127.0.0.1:3306/database_name
This is my project_name __init__
file:
#__init__.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import os
ON_HEROKU = 'ON_HEROKU' in os.environ
if ON_HEROKU:
DB_URL = os.environ.get('CLEARDB_DATABASE_URL')
else:
DB_URL = os.environ.get('LOCAL_MYSQL_URL')
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = DB_URL
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY')
db = SQLAlchemy(app)
db.create_all()
db.session.commit()
However I get the following error after running the app:
if sa_url.drivername.startswith('mysql'):
AttributeError: 'NoneType' object has no attribute 'drivername'
I am trying to make this work following tutorials and answers contributed here on stackoverlow to similar questions, but none of them helped me out so far.
What am I missing here? What's wrong with my mysql driver name?