I'm trying to connect to a MySQL database using Flask-SqlAlchemy, here's my parameter :
SQLALCHEMY_DATABASE_URI = 'mysql://root:[email protected]/database?charset=utf8'
But when I go to the url, I get this error :
AttributeError: 'tuple' object has no attribute 'drivername'
If I change the SQLALCHEMY_DATABASE_URI
to sqlite:///db.sqlite
, it works correctly.
What am I missing ?
Note: I also tried mysql+mysqldb://
, without any luck.
This error often comes up due to their being an extra comma after the URL string. So, instead of...
SQLALCHEMY_DATABASE_URI = 'mysql://root:[email protected]/database?charset=utf8'
...you have...
SQLALCHEMY_DATABASE_URI = 'mysql://root:[email protected]/database?charset=utf8',
The extra comma turns the SQLALCHEMY_DATABASE_URI into a tuple with the string as the only value. SQLAlchemy will skip trying to parse the resulting tuple, but Flask-SQLAlchemy will still try to use the "parsed" result.
This is fixed by removing the extra comma.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With