From 174e9d84e447437efe59f3824d6ea4292320c7f0 Mon Sep 17 00:00:00 2001 From: zhangxunhui Date: Sat, 14 Aug 2021 19:42:50 +0800 Subject: [PATCH] change sqlalchemy.url --- app/db/alembic/env.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/db/alembic/env.py b/app/db/alembic/env.py index b9c7472..e821ca3 100644 --- a/app/db/alembic/env.py +++ b/app/db/alembic/env.py @@ -28,7 +28,9 @@ fileConfig(config.config_file_name) from app.db.tables import sqlalchemy_orm target_metadata = sqlalchemy_orm.Base.metadata -config.set_main_option("sqlalchemy.url", ConfigLoader().load_env()["MYSQL_CONNECTION"]) # we need to add this in main option, because the configuration of sqlalchemy.url is in .env.yaml, not in alembic.ini +env = ConfigLoader().load_env() +connection_url = "mysql+mysqldb://{user}:{password}@{host}:{port}/{db}".format(user=env["MYSQL"]["USER"], password=env["MYSQL"]["PASSWORD"], host=env["MYSQL"]["HOST"], port=env["MYSQL"]["PORT"], db=env["MYSQL"]["DB"]) +config.set_main_option("sqlalchemy.url", connection_url) # we need to add this in main option, because the configuration of sqlalchemy.url is in .env.yaml, not in alembic.ini # other values from the config, defined by the needs of env.py, # can be acquired: