[英]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.