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

4

我正在尝试创建/连接一个Postgres数据库到我的Pony ORM Web应用程序。起初,我使用了一个SQLite数据库与Pony ORM,一切都很顺利,但是由于我想把它放在Heroku上,所以需要切换到Postgres。我使用图形化的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')

它将找到用户并连接到本地主机,但不会连接或创建任何数据库,因此当我尝试使用Pony ORM函数(例如为具有属性“username”的User类创建数据库实体)时,我会收到以下错误:“ProgrammingError:column” username“不存在LINE 1:select * from User where username ='user1'”。Pony不会连接或创建Postgres数据库。所以我想知道如何将Postgres数据库连接到Pony ORM应用程序?

2
你的代码是否会调用 generate_mappings(),就像这里描述的一样:https://docs.ponyorm.com/database.html#mapping-entities-to-the-database-tables - bimsapi
1个回答

0
为什么要定义dbname和database? 在Pony连接Postgres时,参数“dbname”无效。 请使用“database”代替“dbname”:
db.bind('postgres', user='notice', password='Notice',
         host='localhost', database='notice_db', port='5432')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接