簡體   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