当前位置: 首页 > 知识库问答 >
问题:

Django.db.utils.OperationalError无法连接到服务器

龚寂弦
2023-03-14
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?
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"?
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'beerad',
        'USER': 'bli1',
        'PASSWORD': '',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

共有1个答案

蔡楚
2023-03-14

可能是一些问题:

>

  • PostgreSQL未运行。用sudo服务postgresql状态
  • 检查它
  • 您的PostgreSQL没有在端口5432上运行。您可以键入sudo netstat-nl grep postgres来检查它

    您在尝试连接到数据库时出现了一些错误,如用户名、密码或数据库名。检查它们是否是postgres要求您连接它的内容,以及您想要访问的db_name。

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

  •  类似资料:
    • 问题内容: 我不确定如何解决此问题 我不知道为什么在尝试以下操作时会出现此错误: 当我尝试连接到postgres时: 问题答案: 可能是一些问题: PostgreSQL没有运行。用sudo检查 你的PostgresSQl不在端口5432上运行。你可以检查其键入 尝试连接到数据库时出现错误,例如用户名,密码或数据库名。检查它们是否是postgres要求你连接的对象,并且这是你要访问的db_name。

    • 我在设置打开班次时遇到问题,并在连接到我的服务器域后收到以下错误: 我不确定这是在告诉我做什么。我尝试按字面意思使用指令,但它无法识别命令。 有什么想法吗?

    • 在我做了和之后,我的postgres遇到了一些问题。我试着卸载postgres并重新安装它,但它并没有那么好用。 这就是我所做的: 现在,在我重新安装homebrew之后,当我使用时,它不显示任何错误消息。 但是我在我的Rails应用程序中运行,它显示: 更新 这对我也管用。

    • 注意:连接是LAN,在隧道模式下工作正常,但速度较慢

    • 我正在尝试连接两个docker容器,一个是posgresql,另一个是python flask应用程序。两者都链接正确,python应用程序中的所有连接变量都直接取自postgres容器中通过链接公开的连接变量,并且与检查postgresql容器时发现的连接变量相同。当我将psql与连接字符串中的精确参数一起使用时,即: 成功连接到postgres容器中的数据库,因此我知道postgres正在通过

    • E/AndroidRuntime:致命异常:main java.lang.Runtime异常:无法连接到Android.Hardware.camera.Native_Setup(本机方法)(Android.Hardware.camera.Open(camera.java:423)(Android.Hardware.camera.Open)(camera.java:384)(ge.baqari.de