2 months ago
What actually happened:
I am deploying a backend service on Railway using Dockerfile deploys. The container starts, then repeatedly crashes during startup with Prisma error P1012 saying Environment variable not found: DATABASE_URL.
What I observed:
- Startup reaches Prisma migrate step and exits before app boot
- Repeated logs show:
- Prisma schema validation get-config wasm
- Environment variable not found: DATABASE_URL
- This happens in production environment
- Service keeps restarting due to on-failure policy
What I already tried:
- Set DATABASE_URL directly in backend service variables
- Deleted and re-added DATABASE_URL
- Used both direct URL and reference-based values from Postgres plugin
- Confirmed Postgres plugin has DATABASE_URL, DATABASE_PUBLIC_URL, PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE
- Redeployed multiple times from latest main commits
- Removed test localhost values after testing
- Added startup fallback logic in project files to derive DATABASE_URL from DATABASE_PUBLIC_URL and PG* variables
- Updated Docker runtime and Railway start command to use unified startup script Expected behavior: Backend service should receive DATABASE_URL (or derived DB variables) and complete startup.
Actual behavior:
Backend runtime still reports DATABASE_URL missing and crashes before app starts.
Extra context:
This appears to be a service variable injection/scope issue at runtime (possibly environment/service binding mismatch), not a Prisma schema issue.
Please investigate why backend runtime environment variables are not being injected into this service deployment, specifically why DATABASE_URL is unavailable at container startup despite being configured and referenced from the attached Postgres plugin. Also confirm whether this service is using stale deployment/start-command configuration instead of the latest repo commit, and advise the exact corrective steps to force variable propagation for production deploys.
6 Replies
Status changed to Awaiting Railway Response Railway • about 2 months ago
Status changed to Open Railway • about 2 months ago
2 months ago
If your Dockerfile runs prisma migrations during the build phase, it will crash because the variables don't exist yet. Try moving your prisma migrations to your Dockerfile CMD (not RUN).
Or you can run your prisma migrations in a custom start command in your service settings > deploy like:/bin/sh -c "npx prisma migrate deploy && node dist/index.js"
darseen
If your Dockerfile runs prisma migrations during the build phase, it will crash because the variables don't exist yet. Try moving your prisma migrations to your Dockerfile `CMD` (not `RUN`). Or you can run your prisma migrations in a custom start command in your **service settings > deploy** like:`/bin/sh -c "npx prisma migrate deploy && node dist/index.js"`
2 months ago
The variables exist, it's just that private networking isn't available during the build phase. OP will need to add a custom pre-deploy command in settings.
0x5b62656e5d
The variables exist, it's just that private networking isn't available during the build phase. OP will need to add a custom pre-deploy command in settings.
2 months ago
When using a Dockerfile, they don't exist during the build phase automatically, unless you use ARG AFAIK. That's why I suggested using the command in CMD or as a custom start command. Predeploy is also a valid solution.
2 months ago
@acefestus Railway only injects service and plugin variables at container runtime, so if prisma migrate executes during the Docker RUN build phase, it fails because DATABASE_URL isn’t populated until the container actually starts. Move prisma generate to your Dockerfile (it doesn't require the DB URL) and run prisma migrate deploy exclusively in your runtime CMD or entrypoint script, verify your Dockerfile contains no ENV DATABASE_URL statement that silently overrides Railway's injection, and force a clean rebuild by adding a trivial Dockerfile change to bust Railway's cached environment state before redeploying.
darseen
If your Dockerfile runs prisma migrations during the build phase, it will crash because the variables don't exist yet. Try moving your prisma migrations to your Dockerfile `CMD` (not `RUN`). Or you can run your prisma migrations in a custom start command in your **service settings > deploy** like:`/bin/sh -c "npx prisma migrate deploy && node dist/index.js"`
24 days ago
Thank you, I was able to fix it
Status changed to Solved Railway • 24 days ago
24 days ago
Thank you, everyone, for replying to my post. I was able to resolve it.
Status changed to Awaiting Railway Response Railway • 24 days ago
Status changed to Solved Railway • 24 days ago


