Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create SQLAlchemy engine, getting error "loaded 'mysqldb' is not async"

I'm trying to replace Databases with SQLAlchemy 1.4 async. When I try to make the engine I get the following error:

sqlalchemy.exc.InvalidRequestError: The asyncio extension requires an async driver to be used. The loaded 'mysqldb' is not async.

I'm making the engine like this:

engine = create_async_engine(SQLALCHEMY_DATABASE_URL, future=True)

What is need to get mysqldb to work with SQLAlchemy async?

like image 731
Brian C. Avatar asked Jan 25 '26 07:01

Brian C.


1 Answers

I figured it out, I was using this URL:

'mysql://someuser:passwd1234@localhost/app_db'

But I needed to be using something like:

'mysql+asyncmy://someuser:asswd1234@localhost/app_db'

I was missing the +asyncmy part to use the asyncmy dialect. I needed to install the package too:

pip install sqlalchemy[asyncio]
like image 187
Brian C. Avatar answered Jan 27 '26 21:01

Brian C.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!