rails: Rails console doesn't use DATABASE_URL environment variable
If I have DATABASE_URL
set and run rails c
the settings in config/database.yml are used even though DATABASE_URL
should override the settings. If I delete database.yml entirely, then I get the following error: Could not load database configuration. No such file - ["config/database.yml"] (RuntimeError)
.
In irb I can run ENV['DATABASE_URL']
and get the correct URL so I know the environment variable is correctly set.
This rails guide seems to indicate that database.yml is optional and indeed I can run a server with rails s
even with no database.yml present.
Perhaps this is by design, but I can’t imagine why the DATABASE_URL
would be ignored when using a rails console.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 1
- Comments: 26 (10 by maintainers)
If you still encounter this problem with Rails 4.2, please try to stop spring with
spring stop
first. Spring will accept the new ENV variable when it starts again.I had the same issue.
spring stop
did not work for me. However it seems to be gem-related. I changed ruby version in rvm, and did freshbundle install
. Then I got intorails console
and it worked!Ran into to the same problem,
rails c
won’t start with this error.After deleting all my gems
rm -Rf ~/.gem
followed bybundle install
,bundle exec rails c
went ok