【问题标题】:Django/Postgresql : Is the server running on host "xxx" and accepting TCP/IP connections on port 5432?Django/Postgresql:服务器是否在主机“xxx”上运行并接受端口 5432 上的 TCP/IP 连接?
【发布时间】:2017-06-09 08:23:22
【问题描述】:

当我在 django 终端中尝试 python manage.py makemigrationsmigraterunserver时,出现此错误;

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 settings

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

在我的远程服务器中,所有端口都由主机打开,防火墙没有问题。

有什么问题?

【问题讨论】:

    标签: django postgresql


    【解决方案1】:

    确保您的计算机上正在运行 postgres。

    【讨论】:

    • 'HOST': 'localhost'', in Django settings.py 解决了我的问题
    猜你喜欢
    • 2018-12-17
    • 2018-01-20
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 2018-06-22
    • 2021-11-29
    • 2020-12-17
    • 1970-01-01
    相关资源
    最近更新 更多