Jim*_*Jim 13 python django postgresql
我终于(想)成功安装了PostgreSQL和de psycopg2(我用的是Windows).顺便说一句,是否有一些方法可以检查它是否正常工作?
嗯,现在的想法是我无法启动服务器,而我键入'python manage.py runserver'它出现了这个(在命令的末尾):
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 8000?
could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 8000?
我已经搜索了很多关于它的文档,例如在本主题中,但我找不到让它正常工作的方法.我在pg_hba和postgresql文件中尝试了几处更改,但没有退出.在这一刻,pg_hba看起来像:
# TYPE  DATABASE        USER            ADDRESS                 METHOD
# IPv4 local connections:
host    all             all             127.0.0.1            md5
# IPv6 local connections:
host    all             all             127.0.0.1            md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5
而postgresql conf看起来像:
# - Connection Settings -
listen_addresses = 'localhost'      # what IP address(es) to listen on;
                # comma-separated list of addresses;
                # defaults to 'localhost'; use '*' for all
                # (change requires restart)
port = 8000             # (change requires restart)
max_connections = 100           # (change requires restart)
# Note:  Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = ''   # comma-separated list of directories
                # (change requires restart)
#unix_socket_group = ''         # (change requires restart)
#unix_socket_permissions = 0777     # begin with 0 to use octal notation
                # (change requires restart)
#bonjour = off              # advertise server via Bonjour
                # (change requires restart)
#bonjour_name = ''          # defaults to the computer name
顺便说一句,我的数据库settings.py看起来像这样:
DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'database1',                      
    'USER': 'root',
    'PASSWORD': '123456',
    'HOST': 'localhost',
    'PORT': '8000',
    }
}
我还没有创建BTW数据库,我应该怎么做?PostgreSQL提示符的应用是什么?
我非常感谢这个问题的帮助,我一直在寻找和尝试,但没有退出.非常感谢你.
编辑1:我尝试将settings.py端口更改为5432,但现在错误消息是相同的,只是更改端口:
could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
配置文件是这样的吗?我应该改变什么吗?我找不到答案.我试过python manage.py runserver并且都指示127.0.0.1:8000和8001,但错误消息没有变化.出了什么问题?非常感谢你.
Ale*_*lig 11
对我而言,postgres没有启动和启用.所以我通过这样做解决了这个问题:
sudo systemctl start postgresql
sudo systemctl enable postgresql
使端口默认为 5432
DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'database1',                      
    'USER': 'root',
    'PASSWORD': '123456',
    'HOST': 'localhost',
    'PORT': '5432',
    }
}
运行命令:
python manage.py runserver 127.0.0.1:8000
如果您使用 Postgresql 并在 mac 上开发,那么您可以使用以下命令启动 Postgresql,它应该可以解决您的问题。
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
并阻止它
pg_ctl -D /usr/local/var/postgres stop -s -m fast
小智 5
尝试删除主机和端口:
# settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'db_name',
        'USER': 'db_user',
        'PASSWORD': 'db_pass',
    }
}
对我来说,问题是在这里指定主机和/或端口。
| 归档时间: | 
 | 
| 查看次数: | 30190 次 | 
| 最近记录: |