Hello. So I have a django app, it was deployed without db and worked fine. I’ve added to dockerfile a new migration step RUN python manage.py migrate. Added also DATABASE_URL to web app.
In settings.py I have -
I’ve tested locally this new update and it worked fine. But when I run fly deploy I get django.db.utils.OperationalError: could not translate host name "db" to address: Name or service not known.
Tried different options, f.e. psql -h ***.flycast -p 5432 -U postgres -W ******** and it returns - psql: error: could not translate host name "***.flycast" to address: nodename nor servname provided, or not known
In app console, I’m getting same error when running directly python manage.py migrate. Restarting db app didn’t work.
postgres@784e439a223258:/$ psql -h ***.flycast
Password for user postgres:
psql (15.3 (Debian 15.3-1.pgdg120+1))
Type "help" for help.
postgres=# \q
I guess that means, that app logic incorrectly interprets database url.
But then, why I can’t do it with just psql, without logging in to db machine. Does it mean, that publicly that host is available only within fly.io environment or I need to modify fly configs to expose postgres db port?
Right… By default, the .flycast and .internal addresses are only accessible to your Fly Machines (excluding the builder).
There are three different ways to allow connections from your local computer, but you needn’t to do so at the moment—if I understand your situation correctly.
If you instead remove the RUN python manage.py migrate from your Dockerfile and put it in a release_command, then things should work out as you intended.
(The builder doesn’t have access to the database—as alluded to above. This confuses a lot of people…)