我正在使用 Python 构建一个网站 Flask框架和 Peewee ORM和 PostgreSQL 作为数据库。在我的 Mac 上开发时效果很好。我现在将安装移至 Ubuntu 12.04 桌面,以便在 Linux 上进行一些测试,但现在我在使用 Postgresql 时遇到了麻烦。在我的 Mac 上,postgres 服务器似乎不需要用户和密码(对开发有利,对生产不利)。在 Ubuntu 上它现在显示
OperationalError: FATAL: role "kramer65" does not exist
kramer65 是我在 Ubuntu 中的常用用户名,因此很明显 postgres 不知道它。我可以使用 postgres 用户登录 psql,但我不知道如何将其添加到 peewee。我有一个配置文件,其中包含:
DATABASE = {
'name': 'mydb',
'engine': 'playhouse.postgres_ext.PostgresqlExtDatabase'
}
我尝试添加 'password': 'mypassword'
和 'username': 'myusername'
,但随后显示 OperationalError: invalid connection option “用户名”
。
知道如何将用户名和密码添加到 peewee 以连接到我的 PostgreSQL 数据库吗?欢迎所有提示!
最佳答案
我从未听说过 peewee,也没有使用过它,但是 example postgres connection from the github 怎么样? 。由于 peewee 似乎使用 psycopg2 进行 Postgres 连接,因此它们的所有连接选项都应该适用。
您需要使用'user': 'yourusername'
而不是'username': 'yourusername'
。
关于python - 如何在 Flask Peewee ORM 中设置 Postgres 用户名和密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22221838/