首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django Postgresql syncdb错误

Django Postgresql syncdb错误
EN

Stack Overflow用户
提问于 2013-10-18 17:24:24
回答 1查看 2K关注 0票数 4

当我运行python manage.py同步数据库时,我得到这个错误:

代码语言:javascript
复制
OperationalError: could not translate host name "localhost" to address: nodename nor servname provided, or not known

我的settings.py文件如下所示:

代码语言:javascript
复制
if "IS_STAGING" in os.environ or "IS_PRODUCTION" in os.environ:
    import dj_database_url
    DATABASES = {'default':dj_database_url.config(default='postgres://localhost')}
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
            'NAME': 'test',                      # Or path to database file if using sqlite3.
            # The following settings are not used with sqlite3:
            'USER': 'test',
            'PASSWORD': 'test',
            'HOST': 'localhost',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
            'PORT': '',                      # Set to empty string for default.
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2013-11-15 12:41:33

我已经多次遇到这个错误了。如果您尝试连接到本地数据库,最好的方法是将主机保留为空字符串:

'HOST': ''

如果这不起作用,那么应该执行以下操作:

'HOST': '127.0.0.1'

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19446073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档