mas*_*iny 40 python django postgresql psycopg2 django-settings
我在使用POSTGRESQL的Django项目设置中遇到问题.
这是我的setting.py数据库设置
DATABASES = {
'default':{
'ENGINE':'django.db.backends.postgresql_psycopg2', # '.postgresql_psycopg2', '.mysql', or '.oracle'
'NAME':'indivo', # Required to be non-empty string
'USER':'indivo', # Required to be non-empty string
'PASSWORD':'ritvik',
'HOST':'', # Set to empty string for localhost.
'PORT':'', # Set to empty string for default.
},
}
Run Code Online (Sandbox Code Playgroud)
现在在postgres后端我所做的是.
rohit@rohit-desktop:~$ sudo su - postgres
postgres@rohit-desktop:~$ createuser --superuser indivo # create a super user indivo
postgres@rohit-desktop:~$ psql # open psql terminal
psql (9.1.8)
Type "help" for help.
postgres=# \password indivo # set the password ritvik
Enter new password:
Enter it again:
postgres=# \q #logout
postgres@rohit-desktop:~$ createdb -U indivo -O indivo indivo #create db indivo
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我尝试syncdb时,我收到了错误.
psycopg2.OperationalError: FATAL: Peer authentication failed for user "indivo"
Run Code Online (Sandbox Code Playgroud)
请帮我解决一下我在这里做错了什么.
jul*_*sar 46
我有类似的问题,并通过添加到settings.py中的数据库设置解决了这个问题,因此您的数据库设置应如下所示:localhostHOST
DATABASES = {
'default':{
'ENGINE':'django.db.backends.postgresql_psycopg2', # '.postgresql_psycopg2', '.mysql', or '.oracle'
'NAME':'indivo', # Required to be non-empty string
'USER':'indivo', # Required to be non-empty string
'PASSWORD':'ritvik',
'HOST':'localhost', # <- Changed from empty string to localhost
'PORT':'', # Set to empty string for default.
},
}
Run Code Online (Sandbox Code Playgroud)
小智 26
默认情况下,在许多Linux发行版中,客户端身份验证设置为"对等",用于与数据库的Unix套接字连接.这是在pg_hba.confpostgresql 的配置文件中设置的.psycopg2 python库文档说明:
- *host*:数据库主机地址(如果未提供,则默认为UNIX套接字)
因此,如果将主机选项留空,则脚本将尝试连接并使用Unix用户名:密码进行身份验证.要修复,您可以:
pg_hba.conf文件以使用md5进行套接字连接,以便使用存储在postrgres DB用户存储中的用户名和密码(不推荐使用,因为这可能会破坏系统用户的身份验证)您需要设置为用户,数据库和感兴趣的源IP pg_hba.conf使用md5身份验证.请参阅文档的客户端身份验证章节.
搜索pg_hba.confStack Overflow以获取更多信息.
| 归档时间: |
|
| 查看次数: |
36241 次 |
| 最近记录: |