Failed to start application: PrismaClientInitializationError: error: Environment variable not found: DATABASE_URL.
godipay
FREEOP

4 months ago

Hello station
I am new to railway, i have been trying to deploy my nestjs+prisma+mysql project but i always get this error:

Failed to start application: PrismaClientInitializationError: error: Environment variable not found: DATABASE_URL.

--> schema.prisma:9

|

8 | provider = "mysql"

9 | url = env("DATABASE_URL")

|

I did a connection: which shows connected
i added my .env variables but used railway variable values but it still didn't go

DB_TYPE="mysql"
DB_HOST="localhost"
DB_PORT="3306"
DB_USERNAME="root"
DB_PASSWORD=""
DB_NAME="nestpsls"
JWT_SECRET="gyudgqowdoygs62873gIHQadjjd"
JWT_EXPIRES_IN="3600s"
PORT="3000"
BASE_URL="http://localhost:3000"
DATABASE_URL="mysql://root:@localhost:3307/nestpsls"

trough. Any suggestions please ?

Attachments

Solved$10 Bounty

13 Replies

Railway
BOT

4 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


fra
HOBBY

4 months ago

if you click "Add a variable reference" you can automatically add the db secrets to your api

Attachments


godipay
FREEOP

4 months ago

Oh thanks, i was able to do that but i have one issue. when i check mysql, i see docker attributted to it. Is there no way i can use just mysql ?
because my application was able to start but its not migrating the tables. (i added: npm run prisma:migrate && npm run prisma:push && npm run start:prod)

I want to also know if i can use the mysql variables without adding the exact names of my app variables.
i ask because the variables are named different from what i uploaded.

waiting for your advice sir


godipay

Oh thanks, i was able to do that but i have one issue. when i check mysql, i see docker attributted to it. Is there no way i can use just mysql ?because my application was able to start but its not migrating the tables. (i added: npm run prisma:migrate && npm run prisma:push && npm run start:prod)I want to also know if i can use the mysql variables without adding the exact names of my app variables.i ask because the variables are named different from what i uploaded.waiting for your advice sir

noahd
EMPLOYEE

4 months ago

Docker acts like a "wrapper" around services like MySQL. You cant run a bare metal version of it.
When hosted it'll give you a connection string which your app can connect to and start up on.


noahd

Docker acts like a "wrapper" around services like MySQL. You cant run a bare metal version of it. When hosted it'll give you a connection string which your app can connect to and start up on.

noahd
EMPLOYEE

4 months ago

Pretty good read on docker and why its used: https://sematext.com/glossary/docker/

Unless set otherwise, prisma only recognized DATABASE_URL but you can change it with something like:

datasource db {

provider = "mysql"

url = env("DB_CONNECTION_STRING") <- change this thingy here to be whatever you want.

}


godipay
FREEOP

4 months ago

i have done the connection but i get this error when deploying even though i added the url

Error: P1001: Can't reach database server at mysql.railway.internal:3306


godipay

i have done the connection but i get this error when deploying even though i added the urlError: P1001: Can't reach database server at mysql.railway.internal:3306

noahd
EMPLOYEE

4 months ago

If you open your mysql deployment and look for private connection string! Just use this instead. Make sure its in the same project


fra
HOBBY

4 months ago

is the db up and running? did you enable the serverless option? maybe it is sleeping....are you able to open the db form your local machine using the public url?

I suggest to add all the db variables using the dropdown, you can update the name of the variable as you want, but don't touch the value of the variable


godipay
FREEOP

4 months ago

Am probably not getting it correctly because i have done all but still getting this error:
Error: P1001: Can't reach database server at mysql.railway.internal:3306

Please make sure your database server is running at mysql.railway.internal:3306.

and thats actullat what i have as host in the mysql plugin.

Attachments


fra
HOBBY

4 months ago

is the db running? can you check if the db is up (connecting to it using the public url from your local machine), and also can you check if there are errors in the db logs?


godipay
FREEOP

4 months ago

i think the db is running coz it railway shows a green border round its favicon in the broswer when i open the plugin.
Anyone that can help me directly ?


christian
EMPLOYEE

3 months ago

Please try this:

  1. Go to your Service > Variables page.

  2. Click the three-dot menu next to your DATABASE_URL variable, and select Edit.

  3. Replace the existing value with ${{MySQL.MYSQL_URL}} and save.

  4. Deploy the staged changes.

This should set your application to communicate with your service over the built-in private network.

Read about Private Networking and Reference Variables in the Docs.


Status changed to Awaiting User Response Railway 3 months ago


godipay
FREEOP

3 months ago

Hello, i successfully fixed it
my problem is at the level displaying pictures in my app
in my nestjs backend, i have a public folder that sets diff folders for diff purposes bit when i upload an image, its stores the id but cant display the image.
how can i set this public folder on mysql in railway, or how do i make the pictures show?
Thanks


Status changed to Awaiting Railway Response Railway 3 months ago


Status changed to Solved brody 3 months ago


Loading...