I have a Django project with the following DB config:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'feedread',
'USER': 'feedread',
'PASSWORD': 'feedread',
'HOST': os.getenv('PG_HOST') or 'db',
'PORT': '5432',
}
}
However, locally in development I am using docker-compose so the db listens at the db
hostname. I’ve looked through the Django docs and it seems like there is no way to specify a different hostname during testing.
I am using os.getenv('PG_HOST')
where PG_HOST is set to localhost
but it feels like a hack. The alternative would be to add 127.0.0.1 db
to /etc/hosts
but that also feels like a hack.
Has anyone done something like this before? Is there really no way to have a different hostname for testing?