a month ago
The DATABASE URL is not working. Even when I am putting in front of the commands.
Pinned Solution
a month ago
Sorry for the confusion.
If I understand correctly, you're trying to run the command rails console inside your service container, while manually assigning a DATABASE_URL variable temporarily just for this session. (Correct me if I'm wrong).
In this case, you'd need to use railway ssh, as railway run runs the command locally with the environment variables from your service. (https://docs.railway.com/guides/cli#local-development)
You'd SSH into your container, then run your DATABASE_URL="" rails console command.
7 Replies
a month ago
Can you give a bit more context? What are you trying to do?
a month ago
Running this does not update DATABASE_URL for me: DATABASE_URL="[internal DB URL]" railway run rails console
Once inside the console I can run ActiveRecord::Base.establish_connection("[internal DB URL]")
a month ago
You should be using railway variable to update service variables.
a month ago
If you're just trying to SSH into the container/run a command within the container, you'll need to do DATABASE_URL= within the SSH session, or add the DATABASE_URL variable to the service.
Running DATABASE_URL outside of the container will only set the variable in your local machine, not the container itself.
a month ago
Are you saying to run railway ssh and then set the DATABASE_URL for that current session? I only need the DATABASE_URL to be used for that SSH/Console session. I don't need to change the variable on the service itself. I need to be able to connect to the DB on my local machine while in Rails Console.
This isn't blocking me at the moment as I found a work around. I also realized I could add and update records on the DB services as well, which is great!
a month ago
Sorry for the confusion.
If I understand correctly, you're trying to run the command rails console inside your service container, while manually assigning a DATABASE_URL variable temporarily just for this session. (Correct me if I'm wrong).
In this case, you'd need to use railway ssh, as railway run runs the command locally with the environment variables from your service. (https://docs.railway.com/guides/cli#local-development)
You'd SSH into your container, then run your DATABASE_URL="" rails console command.
a month ago
Gotcha. That makes sense. I saw some other posts that you can put the variable in front of railway run but that wasn't working.
The way you stated works as expected. Thanks!
Status changed to Solved brody • about 1 month ago
