问题描述
我正在设置与 Django 3 和 Gitlab CI 的持续集成。
以前用 Django 2 完成过,但现在我正在努力用 Django 3 完成。 显示此警告,我想知道是否是原因:
/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py:304: RuntimeWarning: 通常 Django 将使用到 'postgres' 数据库的连接来避免运行初始化在不需要时(例如,在运行测试时)对生产数据库进行查询。 Django 无法创建到“postgres”数据库的连接,而是使用第一个 Postgresql 数据库。
最后出现这个错误:
django.db.utils.OperationalError:无法将主机名“postgres”转换为地址:名称或服务未知
这是我的配置:
image: python:3.8
services:
- postgres:10.17
variables:
POSTGRES_DB : db_test
POSTGRES_USER : postgres
POSTGRES_PASSWORD : ""
POSTGRES_HOST : postgres
POSTGRES_PORT : 5432
stages:
- tests
cache:
paths:
- ~/.cache/pip/
before_script:
- python -V
- apt-get update && apt install -y -qq python3-pip
- pip install -r requirements.txt
test:
stage: tests
variables:
DATABASE_URL: "postgres://postgres:postgres@postgres:5432/$POSTGRES_DB"
script:
- coverage run manage.py test
- coverage report
coverage: "/TOTAL.+ ([0-9]{1,3}%)/"
如果有人能帮我解决这个问题,我将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)