Working on a project in DRF. I have two databases; local PostgreSQL DB as default, and SQLite3 for testing.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': DB_NAME,
'USER': DB_USERNAME,
'PASSWORD': DB_PASSWORD,
'HOST': DB_HOST,
'PORT': DB_PORT,
},
'test': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test_db.sqlite3',
},
}
Here my .gitlab-ci.yml file
image: python:3.11.1
variables:
DB_HOST: localhost
DB_NAME: db_name
DB_PORT: 5432
DB_USERNAME: username
DB_PASSWORD: password
stages:
- Test
Test-job:
stage: Test
script:
- pip install -r requirements.txt
- cd core
- python manage.py test
After running it, I receive the error below.
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I understand that it cannot connect to the localhost because it’s on a seperate server, so I switched the default and test databases with each other. The job passed, but it lead to other complications with the databases. So I switched them back.
We plan on connecting to AWS RDS for the default DB later, but am being told that the job should pass before that. I spent all day yesterday looking for a solution, but I’ve got nothing.
Is there a way around this issue?