我有一个在名为
tenant_schema
run_migrations_online
中的函数
env.py
我建立了一个模式图
我预料到了
sqlalchemy
要将此迁移操作转换为在所需架构上运行,它似乎试图使用该架构运行sql查询
.
你知道怎么修吗?
:
2018-09-05_17-28_247f3546088f_add_foo_column.py
def upgrade():
op.add_column('derived_table', sa.Column('foo', sa.BigInteger(), nullable=True),
schema='tenant_schema')
这个
联机运行\u迁移\u
功能:
schema = 'other_name' # normally i get the name as an argument from alembic
def run_migrations_online():
connectable = create_engine(get_url(), echo=True)
with connectable.connect() as connection:
# setting up the translation map
conn = connection.execution_options(schema_translate_map={'tenant_schema': schema})
context.configure(
connection=conn,
target_metadata=target_metadata,
include_schemas=True,
version_table_schema=schema,
include_object=include_object,
)
with context.begin_transaction():
context.run_migrations()
例外情况(完全回溯太长,信息量不大):
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) schema "tenant_schema" does not exist
[SQL: 'ALTER TABLE tenant_schema.derived_table ADD COLUMN foo BIGINT']
(Background on this error at: http://sqlalche.me/e/f405)
ALTER TABLE tenant_schema.derived_table
而不是想要的
ALTER TABLE other_name.derived_table