1

I'm setting up a continuous integration with Django 3 and Gitlab CI.

Having done it previously with Django 2 but now I'm struggling to get things done with Django 3. This warning is shown and I'm wondering if it's the reason :

/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py:304: RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.

And this error at the end :

django.db.utils.OperationalError: could not translate host name "postgres" to address: Name or service not known

Here is my config :

    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}%)/"

Will be grateful if somebody can help me fix this.

sk001
  • 561
  • 6
  • 27

0 Answers0