繁体   English   中英

如何在Pony ORM中创建/连接postgres数据库?

[英]How to create/connect a postgres database in Pony ORM?

我正在尝试创建/连接postgres数据库到我正在做的Pony ORM Web应用程序。 起初我使用了一个带有Pony ORM的sqlite数据库,一切正常但我需要切换到postgres,因为我想把它放在Heroku上。 我使用了图形postgres工具并创建了一个名为“notice_db”的数据库和一个名为notice的postgres用户。 我用pony绑定数据库的代码是:

db = Database()                                                                     
db.bind('postgres', user='notice', password='Notice',host='localhost', database='notice_db', dbname='notice_db', port='5432')

它将找到用户并连接到localhost,但是没有数据库将被连接或创建,因此当我尝试使用Pony ORM函数时,例如为我的User类创建一个具有属性“username”的数据库实体,我收到此错误:“ProgrammingError” :列“用户名”不存在第1行:从用户中选择*,其中username ='user1'“。

Pony没有连接或创建postgres数据库。 所以我想知道如何将postgres数据库连接到Pony ORM应用程序?

为什么要定义dbname和数据库? 参数'dbname'不适用于pony的postgres连接。 使用'database'而不是'dbname':

db.bind('postgres', user='notice', password='Notice',
         host='localhost', database='notice_db', port='5432')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM