【问题标题】:Postgres schemas with Pony ORM带有 Pony ORM 的 Postgres 模式
【发布时间】:2018-02-13 17:38:34
【问题描述】:
如何选择在 PonyORM 中使用的 postgres 架构?
我尝试使用仅对一个名为“test1”的架构具有权限的角色登录,但它将我连接到公共架构。所以,我删除了公共模式,然后它给了我一个错误:
ProgrammingError: no schema has been selected to create in
LINE 1: CREATE TABLE "customers" (
【问题讨论】:
标签:
python
postgresql
orm
ponyorm
【解决方案1】:
您可以通过两种可能的方式做到这一点。
首先是指定你的连接
db = Database()
... # models definition
pg = dict(
provider='postgres',
user='username',
password='pwd',
host='localhost',
database='db',
options='-c search-path=SCHEMA NAME') # here you specify default schema
db.bind(**pg)
db.generate_mapping(create_tables=True)
其次是为实体指定_table_选项
class Person(db.Entity):
_table_ = ('schemaname', 'tablename')
attribute = ...