来自alembic documentation(重点是我):
sqlalchemy.url-通过SQLAlchemy连接到数据库的URL。仅当env.py文件调用它们时才使用此配置值;在“通用”模板中,在run_migrations_offline()函数中对config.get_main_option(“ sqlalchemy.url”)的调用以及在run_migrations_online()函数中对engine_from_config(prefix =“ sqlalchemy。”)的调用是此键所在的位置参考。 如果SQLAlchemy URL应该来自其他来源,例如环境变量或全局注册表,或者如果迁移环境使用多个数据库URL,则鼓励开发人员 env.py 文件以使用适当的任何方法来获取数据库URL。
因此,在这种情况下,sqlalchemy url格式可以被python本身规避和生成。
,
我通过在 config
导入后修改 env.py
对象中的值解决了这个问题:
# this is the Alembic Config object,which provides
# access to the values within the .ini file in use.
config = context.config
# import my custom configuration
from my_app import MY_DB_URI
# overwrite the desired value
config.set_main_option("sqlalchemy.url",MY_DB_URI)
现在 config.get_main_option("sqlalchemy.url")
返回您想要的 MY_DB_URI
。
本文链接:https://www.f2er.com/3005570.html