根据文档,alembic 的模板可以指定为 alembic init --template pylons ./scripts
。但 alembic 仅在其根目录中的一个文件夹 (python_path/lib/python2.7/site-packages/alembic/templates
) 中搜索模板。
有什么方法可以运行自定义模板吗?问题的想法 - 项目设置的自动化,例如避免任何手工更改(例如编辑 env.py
文件)。
最佳答案
正如我在 Alembic 源代码中看到的那样,无法自定义模板目录位置。模板目录通过 Config.get_template_directory() 获取并由 list_templates() 使用。
尽管您可以尝试使用 monkey patch :
from alembic.config import Config
def get_template_directory(self):
return "my/custom/template/directory"
Config.get_template_directory = get_template_directory
# Invoke Alembic code
附注我想知道为什么 Alembic 不使用入口点来收集可用模板。
关于python - 如何在alembic初始化期间使用自定义模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21508255/