所以说我有两个使用database.yml
文件连接的数据库,现在我希望我的sidekiq工作人员也连接到第二个数据库,但是当我从工作人员访问第二个数据库时,sidekiq工作人员最终会给ActiveRecord::NoDatabaseError: Unknown database
我的database.yml如下
development:
adapter: mysql2
database: database
username: username
password: password
host: localhost
test:
adapter: mysql2
database: database
username: username
password: password
host: localhost
production:
adapter: mysql2
database: database
username: username
password: password
host: localhost
seconddatabase:
development:
adapter: mysql2
database: database2
username: username2
password: password2
host: different.localhost
production:
adapter: mysql2
database: database2
username: username2
password: password2
host: different.localhost
我的基本活动记录是
class SecondDatabaseBase < ActiveRecord::Base
establish_connection configurations['seconddatabase'][ENV['RAILS_ENV']]
self.abstract_class = true
end
我用来查询表的实际活动记录类是
class TableToQuery < SecondDatabaseBase
self.table_name = 'table_to_query'
end
现在,当我运行以下查询时
TableToQuery.where(:column => 1)
它给我一个错误,说
ActiveRecord::NoDatabaseError: Unknown database 'seconddatabase'