In this FastAPI projet I'm trying to load an environment variable called DATABASE_URL inside Alembic env.py file and use it as follows:
env.py
from alembic import context
import os
from dotenv import load_dotenv
config = context.config
load_dotenv('./../.env')
DATABASE_URL = os.environ.get("DATABASE_URL")
config.set_main_option('sqlalchemy.url', DATABASE_URL)
.env
DATABASE_URL=mysql+mysqldb://root:123321@localhost/MyDatabase
My .env file location relative to env.py:
alembic/
env.py
app/
.env
...
I tried using the python shell to check whether DATABASE_URL is being loaded and it did. Wrapping the DATABASE_UR in str() did not help.
Could you show me a way to resolve this? Thank you!