我正在尝试将我的数据库环境设置为staging
,但我收到此错误:
$ bin/rails db:environment:set RAILS_ENV=staging
rails aborted!
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
/Users/bfruitman/workspace/hired/config/environment.rb:5:in `<top (required)>'
/Users/bfruitman/workspace/hired/bin/rails:9:in `<top (required)>'
/Users/bfruitman/workspace/hired/bin/spring:14:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:environment:set => environment
(See full trace by running task with --trace)
我已经在database.yml
中输入了一个条目:
staging:
<<: *heroku
但这显然不够好。我应该在哪里定义staging
?
答案 0 :(得分:1)
更改数据库环境的最佳方法是使用psql:
update ar_internal_metadata set value = 'staging' where key = 'environment';
将staging
替换为您要使用的任何环境。
答案 1 :(得分:0)
default: &default
adapter: postgresql
staging:
<<: *default
还要确保已设置RAILS_ENV
env var。
答案 2 :(得分:-1)
您可能需要添加文件:config/environments/staging.rb
,默认情况下不包含该文件,我通常首先复制我的production.rb,然后进行任何特定于阶段的更改(如果需要)。
cp config/environments/production.rb config/environments/staging.rb