我正在尝试创建/连接一个 postgres 数据库到我正在做的 Pony ORM 网络应用程序。起初我使用带有 Pony ORM 的 sqlite 数据库并且一切正常但我需要切换到 postgres 因为我想把它放在 Heroku 上。我使用了图形化的 postgres 工具并创建了一个名为“notice_db”的数据库和一个名为 notice 的 postgres 用户。我用小马绑定(bind)数据库的代码是:
db = Database()
db.bind('postgres', user='notice', password='Notice',host='localhost', database='notice_db', dbname='notice_db', port='5432')
它会找到用户并连接到本地主机,但不会连接或创建任何数据库,所以当我尝试使用 Pony ORM 函数时,比如为我的用户类创建一个数据库实体,它具有属性“用户名”,我得到这个错误:“编程错误:列“用户名”不存在第 1 行:从用户中选择 *,其中用户名 = 'user1'”。
Pony 不连接或创建 postgres 数据库。所以我想知道如何将 postgres 数据库连接到 Pony ORM 应用程序?
最佳答案
为什么要定义 dbname 和 database? 参数“dbname”不适用于来自 pony 的 postgres 连接。 使用“数据库”而不是“数据库名称”:
db.bind('postgres', user='notice', password='Notice',
host='localhost', database='notice_db', port='5432')
关于python - 如何在 Pony ORM 中创建/连接 postgres 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35069600/