【问题标题】:Can I use .py file instead of .ini file on alembic?我可以在 alembic 上使用 .py 文件而不是 .ini 文件吗?
【发布时间】:2015-09-23 04:11:22
【问题描述】:

我想使用 alembic.py 而不是 alembic.ini 进行配置。
但我找不到任何此类配置的示例。
有什么办法不使用alembic.ini?

【问题讨论】:

    标签: python sqlalchemy migration alembic


    【解决方案1】:

    你在找this:

    from alembic.config import Config
    alembic_cfg = Config()
    alembic_cfg.set_main_option("script_location", "myapp:migrations")
    alembic_cfg.set_main_option("url", "postgresql://foo/bar")
    alembic_cfg.set_section_option("mysection", "foo", "bar")
    

    【讨论】:

    • 这正是我想要的。执行 alembic 命令时如何指定此自定义配置 .py 文件?
    • 将此文件另存为alembic_config_file.py,并在开始时从您的应用程序中导入。
    • 另外,请考虑upvoting,如果对您有帮助,请点击打勾将其标记为答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    相关资源
    最近更新 更多