数据库未配置。可用:[](ActiveRecord :: AdapterNotSpecified)

时间:2022-05-24 16:57:54

Trying to configure multiple databases to put logs differently in an different database

尝试配置多个数据库以在不同的数据库中以不同方式放置日志


default: 
  adapter: mysql2
  host: xxx.xxx.xxx.xxx
  password: root
  pool: 5
  timeout: 5000
  username: root
development: 
  adapter: mysql2
  database: abc
  encoding: utf8
  host: xxx.xxx.xxx.xxx
  password: root
  pool: 5
  timeout: 5000
  username: root
log_database_development: 
  adapter: mysql2
  database: abc_logs
  encoding: utf8
  host: xxx.xxx.xxx.xxx
  password: root
  pool: 5
  timeout: 5000
  username: root
log_database_test: 
  adapter: mysql2
  database: abc_logs
  encoding: utf8
  host: xxx.xxx.xxx.xxx
  password: root
  pool: 5
  timeout: 5000
  username: root
test: 
  adapter: mysql2
  database: abc
  encoding: utf8
  host: xxx.xxx.xxx.xxx
  password: root
  pool: 5
  timeout: 5000
  username: root

but when i am trying to run

但是当我想跑的时候

rake db:migrate RAILS_ENV=development

rake db:migrate RAILS_ENV = development

i am getting exception

我正在例外

ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:248:in `resolve_symbol_connection': 'log_database_development' database is not configured. Available: [] (ActiveRecord::AdapterNotSpecified)

my model which is trying to access this database is

我试图访问这个数据库的模型是

class AccessLog < ActiveRecord::Base
  establish_connection "log_database_#{Rails.env}"
end

now i am not getting what is wrong in my model or connection, Can you please help me out ?

现在我的模型或连接没有出错,能帮帮我吗?

1 个解决方案

#1


0  

When providing the argument of a configured section to establish_connection you need to provide it as a symbol:

将配置节的参数提供给establish_connection时,需要将其作为符号提供:

establish_connection :"log_database_#{Rails.env}"

or...

establish_connection "log_database_#{Rails.env}".to_sym

#1


0  

When providing the argument of a configured section to establish_connection you need to provide it as a symbol:

将配置节的参数提供给establish_connection时,需要将其作为符号提供:

establish_connection :"log_database_#{Rails.env}"

or...

establish_connection "log_database_#{Rails.env}".to_sym