加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – Django Postgresql syncdb错误

发布时间:2020-12-20 13:37:51 所属栏目:Python 来源:网络整理
导读:当我运行 python manage.py syncdb时,我收到此错误: OperationalError: could not translate host name "localhost" to address: nodename nor servname provided,or not known 我的settings.py文件如下所示: if "IS_STAGING" in os.environ or "IS_PRODUC
当我运行 python manage.py syncdb时,我收到此错误:

OperationalError: could not translate host name "localhost" to address: nodename nor servname provided,or not known

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

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.
        }
    }

解决方法

我多次出现此错误.如果您尝试连接到本地数据库,最好的办法是将主机保留为空字符串:

‘主持人’:”

如果这不起作用,以下应该:

‘主持人’:’127.0.0.1’

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读