postgresql - 将 postgresql 模式传递给 alembic 迁移

标签 postgresql sqlalchemy alembic

我有一个 postgresql 数据库,我想在 DSN 中传递 postgresql 架构名称,如下所示:postgresql://login:password@postgreshost/dbname?schema=my_schema。我知道我可以在 op.create_table 等迁移操作中指定 schema 关键字。不幸的是,upgrade() 和 downgrade() 函数没有可以传递 postgres 架构的参数。有没有办法将模式名称传递给 op.create_table() 而无需对其进行硬编码?

最佳答案

如果这应该始终成为默认架构,您可以更改 schema search path对于 Postgres 用户:

alter user the_user set search_path = my_schema;

这将使所有使用非限定标识符的语句使用 my_schema 作为默认值。

关于postgresql - 将 postgresql 模式传递给 alembic 迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50467928/

相关文章:

python - flask-admin:如何在编辑和创建表单时显示有意义的外键信息?

python - SQLAlchemy 错误?我不知道

python - Alembic 不处理 column_types.PasswordType : Flask+SQLAlchemy+Alembic

python - Alembic:从脚本内的模式比较获取 SQL 输出

python - 如何在 Alembic 升级脚本中执行插入和更新?

java - JPA/Hibernate 适用于 Postgresql,但不适用于 Mysql

database - 优化 Redshift 查询的大 IN 条件

python - 如何在没有邮件模板 odoo 9 的情况下发送电子邮件

ruby-on-rails - 需要将 bool 值从 Postgres (== String) 转换为 Ruby bool 值

python - 找出 sqlalchemy orm 中的根引用