简体   繁体   English

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

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

I'm trying to create/connect a postgres database to a Pony ORM web application that I'm doing. 我正在尝试创建/连接postgres数据库到我正在做的Pony ORM Web应用程序。 At first I used a sqlite database with Pony ORM and everything worked fine but I need to switch to postgres since I want to put it up on Heroku. 起初我使用了一个带有Pony ORM的sqlite数据库,一切正常但我需要切换到postgres,因为我想把它放在Heroku上。 I used the graphic postgres tool and created a database called "notice_db" and a postgres user called notice. 我使用了图形postgres工具并创建了一个名为“notice_db”的数据库和一个名为notice的postgres用户。 My code for binding the database with pony is: 我用pony绑定数据库的代码是:

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

It will find the user and connect to localhost but no database will be connected or created so when I try to use the Pony ORM functions like creating an database entity for my User class which has the attribute "username" I get this error: "ProgrammingError: column "username" does not exist LINE 1: select * from User where username = 'user1'". 它将找到用户并连接到localhost,但是没有数据库将被连接或创建,因此当我尝试使用Pony ORM函数时,例如为我的User类创建一个具有属性“username”的数据库实体,我收到此错误:“ProgrammingError” :列“用户名”不存在第1行:从用户中选择*,其中username ='user1'“。

Pony does not connect to or create postgres database. Pony没有连接或创建postgres数据库。 So I wonder how I connect a postgres database to a Pony ORM application? 所以我想知道如何将postgres数据库连接到Pony ORM应用程序?

Why are you defining dbname and database? 为什么要定义dbname和数据库? The parameter 'dbname' doesn't work for a postgres connection from pony. 参数'dbname'不适用于pony的postgres连接。 Use 'database' instead of 'dbname': 使用'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