django.db.utils.OperationalError无法连接到服务器 [英] django.db.utils.OperationalError Could not connect to server

查看:4041
本文介绍了django.db.utils.OperationalError无法连接到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何解决这个问题

I am not sure how to fix this issue

我不知道为什么当我尝试 runserver

I have no idea why I am getting this error when I try to runserver:

Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x1085589b0>
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 222, in wrapper
    fn(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
    self.check_migrations()
  File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 159, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Library/Python/2.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/Library/Python/2.7/site-packages/django/db/migrations/loader.py", line 184, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/Library/Python/2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/Library/Python/2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.get_table_list(self.connection.cursor()):
  File "/Library/Python/2.7/site-packages/django/db/backends/__init__.py", line 165, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/Library/Python/2.7/site-packages/django/db/backends/__init__.py", line 138, in _cursor
    self.ensure_connection()
  File "/Library/Python/2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
    self.connect()
  File "/Library/Python/2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Library/Python/2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
    self.connect()
  File "/Library/Python/2.7/site-packages/django/db/backends/__init__.py", line 122, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/Library/Python/2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 134, in get_new_connection
    return Database.connect(**conn_params)
  File "/Library/Python/2.7/site-packages/psycopg2/__init__.py", line 164, in connect
    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 "127.0.0.1" and accepting
        TCP/IP connections on port 5432?

当我尝试连接到postgres:

When I try to connect to postgres:

psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

settings.py:

settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'beerad',
        'USER': 'bli1',
        'PASSWORD': '',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}


推荐答案

一些问题:


  1. PostgreSQL没有运行。检查它与sudo 服务postgresql状态

  2. 您的PostgresSQl没有在端口5432上运行。您可以检查它键入 sudo netstat -nl | grep postgres

您的用户名,密码或数据库名称连接到您的数据库时出错。检查他们是什么postgres要求您连接它,那是您要访问的db_name。

You have something wrong trying to connect to your db like the username, the password or the databasename. Check that they are what postgres ask for you to connect it and that is the db_name that you want to access to.

postgres中postmaster.pid的问题。这可能是因为关机无法完成。它提醒一个pid活着,不允许你的服务器启动。要修复它,您必须:

Problems with postmaster.pid in postgres. It can happen because of a shutdown unproperly done. It makes to remind a pid alive that doesn't allow your server start. To fix it you have to:

 * rm /usr/local/var/postgres/postmaster.pid 
 * pg_resetxlog -f /usr/local/var/postgres

之后,如果你做Postgres的runserver

After this it should run properly if you make the runserver of postgres

Mac OSX中的帮助:如何在Mac OS X上启动PostgreSQL服务器?

Help in Mac OSX: How to start PostgreSQL server on Mac OS X?

这篇关于django.db.utils.OperationalError无法连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆