如何为db:environment:set定义环境?

时间:2017-04-28 19:38:17

标签: ruby-on-rails postgresql ruby-on-rails-5.1 postgres-9.6

我正在尝试将我的数据库环境设置为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

3 个答案:

答案 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