简体   繁体   English

无法将主机名“postgres”转换为地址:未知主机

[英]could not translate host name “postgres” to address: Unknown host

Setting up a Django project but I am getting a warning about setting up postgres as shown in the title, but I am unsure what this means.设置 Django 项目,但我收到有关设置postgres的警告,如标题所示,但我不确定这意味着什么。

Full warning message:完整的警告信息:

RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': could not translate host name "postgres" to address: Unknown host

And here is how I define postgres in my settings.py :这是我在settings.py定义postgres

DATABASES = {
"default": {
    "ENGINE": "django.db.backends.postgresql_psycopg2",
    "NAME": os.environ.get("DB_NAME", "dbname"),
    "USER": os.environ.get("DB_USER", "dbuser"),
    "PASSWORD": os.environ.get("DB_PASSWORD", "dbpassword"),
    "HOST": os.environ.get("DB_HOST", "postgres"),
    "PORT": os.environ.get("DB_PORT", "5432"),
}

} }

Would it possible for someone to walk me through what is going wrong here?有人可以带我了解这里出了什么问题吗? I have no idea.我不知道。

In order to use django with postgresql you need a reachable postgresql server.为了在 postgresql 中使用 django,您需要一个可访问的 postgresql 服务器。

You can install and run it locally : https://www.postgresql.org/download/您可以在本地安装和运行它: https : //www.postgresql.org/download/

Then you postgresql server will be reachable on your localhost interface.然后你可以在你的本地主机界面上访问你的 postgresql 服务器。 This DB_HOST config variable represent the address where your django server should contact your postgresql server.这个 DB_HOST 配置变量代表你的 django 服务器应该联系你的 postgresql 服务器的地址。

So you can change the default value of your DB_HOST environment variable from "postgres" to "localhost", or directly set it into your environment ( using a .env file for example )因此,您可以将 DB_HOST 环境变量的默认值从“postgres”更改为“localhost”,或者直接将其设置到您的环境中(例如使用 .env 文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发生异常:OperationalError 无法将主机名“db”转换为地址:未知主机 - Exception has occurred: OperationalError could not translate host name “db” to address: Unknown host Postgres 错误无法将主机名“postgres”转换为地址:名称或服务未知 - Postgres error could not translate host name "postgres" to address: Name or service not known 无法使用 Postgres、Docker Compose 和 Psycopg2 将主机名“db”转换为地址 - Could not translate host name "db" to address using Postgres, Docker Compose and Psycopg2 pg_dump:错误:无法将主机名“localhost”转换为地址:未知服务器错误 - pg_dump: error: could not translate host name "localhost" to address: Unknown server error psycopg2.OperationalError:无法将主机名“xxxxxx.us-east-1.rds.amazonaws.com”转换为地址:未知主机 - psycopg2.OperationalError: could not translate host name "xxxxxx.us-east-1.rds.amazonaws.com" to address: Unknown host 无法将主机名“db”转换为地址:名称解析暂时失败 - could not translate host name "db" to address: Temporary failure in name resolution Heroku + Postgres:psycopg2.OperationalError:无法翻译主机名“无” - Heroku + Postgres: psycopg2.OperationalError: could not translate host name “None” Docker:当使用容器名称从一个容器连接到另一个容器时,如何修复“无法将主机名”postgres“转换为地址”? - Docker: How to fix “could not translate host name ”postgres“ to address” when connecting from one container to another using container name? Docker:运行容器时“无法将主机名“plagdb”转换为地址” - Docker: "could not translate host name "plagdb" to address" when running a container Django Docker:django.db.utils.OperationalError:无法将主机名“db”转换为地址:名称或服务未知 - Django Docker: django.db.utils.OperationalError: could not translate host name “db” to address: Name or service not known
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM