-1

Currently attempting to implement backend CI for a project using Django for the server and PostgreSQL for the database. I'm automating this using GitHub Actions to occur whenever a pull request is done, but when it tries to attempt migrations, it gives me the error mentioned in the title. I've temporarily changed it to run on a push to the branch so I don't have to make a new pull request every time I want to test it.

This is the relevant bits from the .yml file:

name: Backend CI

on:
  push:
    branches:
      - test-branch
jobs:
  build:
    runs-on: ubuntu-latest

    defaults:
      run:
        working-directory: server

    services:
      db:
        image: postgres
        env:
          POSTGRES_HOST: db
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: password
          POSTGRES_DB: github-actions
        ports:
          - 5432:5432
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      ...

      - name: Run Migrations
        env:
          API_SECRET_KEY: secret-key
          POSTGRES_HOST: db
          POSTGRES_PASSWORD: password
          POSTGRES_PORT: 5432
        run: |
          source .venv/bin/activate
          python manage.py migrate

      ...

What I expected to happen was for migrations to run smoothly, but it instead throws me the error from the title.

What I've tried so far:

  • Specifying hostname for the db
  • Providing the expected hostname and password for the server to connect to

Someone I asked told me to check if I'm running Django in the container and I think I am? I was under the assumption that Django was running in the same virtual environment as the database would be.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 24 '23 at 09:46

1 Answers1

0

Strangely what seemed to work was unspecifying a hostname, I took out POSTGRES_HOST: db from the services block and changed db to localhost in the host name under the migrations bit.