lim*_*lim 9 python django postgresql sqlalchemy
根据这本手册,我写了一个简单的sqlalchemy-django模型:http://lethain.com/replacing-django-s-orm-with-sqlalchemy/,这对我很有帮助.
我的Django连接到远程postgresql数据库,具有以下设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'wetlab_dev', # Or path to database file if using sqlite3.
'USER': 'limlim', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': 'cab-27', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
Run Code Online (Sandbox Code Playgroud)
它在几天前对我有用,但现在当我再次尝试加载"主页"时,它会显示以下错误消息:
(OperationalError) FATAL: Ident authentication failed for user "limlim"
Run Code Online (Sandbox Code Playgroud)
sqlalchemy引擎配置是:
CONNECTION_STR = 'postgresql://limlim:@cab-27/wetlab_dev'
engine = sqlalchemy.create_engine(CONNECTION_STR)
Run Code Online (Sandbox Code Playgroud)
似乎我没有更改任何与数据库配置相关的内容,但我仍然收到此错误消息.
此外,当我尝试使用我的用户名连接到远程服务器上的数据库时,我成功了,所以我想这不是我的用户名访问此数据库的权限问题.
可以做些什么来克服这个错误?
小智 10
@Craig是对的,必须更新文件pg_hba.conf中数据库用户的身份验证方法,这是我所做的:
sudo nano /var/lib/pgsql/data/pg_hba.conf
转到文件底部,然后将 IPv4 和 IPv6 行上的方法从 ident 更改为 md5:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5 # <- here
# IPv6 local connections:
host all all ::1/128 md5 # <- and here
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
Run Code Online (Sandbox Code Playgroud)
快乐编码:)
| 归档时间: |
|
| 查看次数: |
12687 次 |
| 最近记录: |