返回 首页

Alembic隐藏数据库配置信息


Alembic数据库迁移使用参考: https://blog.csdn.net/deerlux/article/details/50181997


此迁移工具的详细配置信息在alembic.ini文件中, 其中包括

sqlalchemy.url = driver://user:pass@localhost/dbname

为了防止不小心将密码信息提交, 可将此行删除,并修改alembic/env.py

import sys

sys.path.append(os.path.realpath('.'))
from planet.common.base_model import DB_PARAMS

from planet import models
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.


config = context.config
config.set_main_option('sqlalchemy.url', DB_PARAMS)  # 关键行

target_metadata = None

target_metadata = models.Base.metadata

登录