当我在 Django 终端中尝试 python manage.py makemigrations
或 migrate
或 runserver
时,出现此错误;
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "my_remote_ip" and accepting
TCP/IP connections on port 5432?
我会给你我的settings.py - 数据库设置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'my_database_name',
'USER': 'my_user',
'PASSWORD': 'my_password',
'HOST': 'my_remote_ip', <-- and also I try localhost
'PORT': '', <-- default 5432
}
}
这是我的 postgresql.conf
设置;
listen_addresses = 'my_remote_ip'
port = 5432
我也试试
listen_addresses = '*'
port = 5432
这是我的 pg_hba.conf
设置;
#IPv4 local connections:
host all all my_remote_ip/32 md5
#IPv6 local connections:
host all all ::1/128 md5
在我的远程服务器中,所有端口都由主机打开,防火墙没有问题。
问题是什么?
最佳答案
确保 postgres 正在您的计算机上运行。
关于 Django /PostgreSQL : Is the server running on host "xxx" and accepting TCP/IP connections on port 5432?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41829842/