在创建我的虚拟机后,我遵循了这个教程: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04 然后我编辑了settings.py、pg_hba.conf和postgresql.conf文件。
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresqlpsycopg2',
'NAME': '.....',
'USER': '....',
'PASSWORD': '....',
'HOST': '127.0.0.1',
'PORT': '5432',
STATICROOT = os.path.join(BASE_DIR, 'static/') - at the end of the page
当然,我也更改了ALLOWED HOSTS = ['....'],用我的droplet IP替换。
postgresql.conf listen_address is set to '*'
pg_hba.conf 文件:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5
也允许防火墙,并设置例外,允许5432端口通过。有什么想法吗?