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.