django postgres无法连接到服务器 [英] django postgres could not connect to server

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

问题描述

我正在使用virtualenv在Django项目上使用以下代码的Django = = 1.7.6argparse == 1.2.1psycopg2 == 2.6wsgiref == 0.1.2

hi im working on a django project with virtualenv that is using the following Django==1.7.6 argparse==1.2.1 psycopg2==2.6 wsgiref==0.1.2

但是当我尝试 python manage.py runserver 时,它给了我这个错误

but when i try python manage.py runserver it gives me this error

Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x7f0574e8c0c8>
Traceback (most recent call last):
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 222, in wrapper
    fn(*args, **kwargs)
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
    self.check_migrations()
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 159, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
    self.build_graph()
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 183, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/home/marashen/.virtualenvs/192/local/lib/python2.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 "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 165, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 138, in _cursor
    self.ensure_connection()
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
    self.connect()
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
    self.connect()
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 122, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 130, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/home/marashen/.virtualenvs/192/local/lib/python2.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?

我的settings.py是

my settings.py is

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

我还检查了postgresql.conf,它使用5432作为端口.

i also checked the postgresql.conf and it is using 5432 as port.

另一个奇怪的是,我不小心在我的virtualenv之外运行了server,它正常工作,但Django版本是1.6.

another odd thing is that i accidentally runserver outside my virtualenv and it worked but the django version is 1.6.

请帮助我,非常感谢!

推荐答案

也许您可以尝试以下方法:

may be you can try with this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'elfmsdb',
        'USER': 'postgres',
        'PASSWORD': '',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

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

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