Procfile 'release' database migration running prior to database start
sjpriest
HOBBYOP

9 months ago

I posted this on the Help Station, too, but the Discord seems a bit more active.

I am running Django + Postgres. Recently, I added Uvicorn to support async. Since the default Django run command is typically 'runserver', I added a Procfile to my project to use a 'gunicorn' command. All of this works without issue.

However, database migrations ('python manage.py migrate') don't seem to be occurring, presumably because of the switch to the Procfile. I've tried adding a 'release: python manage.py migrate' line, but this fails, presumably because the database hasn't started when the command runs.

psycopg2.OperationalError:

May 05 07:37:24

could not translate host name "postgres.railway.internal" to address: Name or service not known

I'm curious what the best way to resolve this is. Claude suggests replacing the command with a script that retries a few dozen times. The docs indicate that "You can control the order your services start up with Reference Variables," but I ensured that my Django service has a reference variable to the Postgres database and that doesn't seem to have resolved anything.

4 Replies

sjpriest
HOBBYOP

9 months ago

Project ID is: 1639f59c-5c44-42c3-9a46-6b7566be82f3


brody
EMPLOYEE

9 months ago

Hello,

For future reference, please do not create duplicate posts across platforms, an engineer may answer you in Discord, and then a different engineer may answer you in central station, meaning that the duplicate post that has already been answered has taken up valuable time for the person who unknowingly answers an already answered question.

Either way, you would not want to be using a release option in the Procfile, you are looking for the pre-deploy command in the service settings -


sjpriest
HOBBYOP

9 months ago

Ah, thank you, I will try that tomorrow. Including the migration step in a script referenced by the Procfile also solved the problem.


brody
EMPLOYEE

9 months ago

sounds good!


Loading...