简体   繁体   English

Ruby On Rails 5.2和多个数据库

[英]Ruby On Rails 5.2 and Multiple Databases

I have three different database systems my Rails application needs to access at the same time. 我的Rails应用程序需要同时访问三个不同的数据库系统。

We have SQL Server, an Oracle server, and of course Postgres. 我们有SQL Server,Oracle服务器,当然还有Postgres。

I have tried to figure out how to achieve the ability to grab data from all three (multiverse, etc..). 我试图弄清楚如何实现从所有三个对象(multiverse等)中获取数据的能力。

All I get is a vague error: 我得到的只是一个模糊的错误:

ActiveRecord::Base.establish_connection ActiveRecord::AdapterNotSpecified in UsersController#index database configuration does not specify adapter UsersController#index数据库配置中的ActiveRecord :: Base。Establishment_connection ActiveRecord :: AdapterNotSpecified没有指定适配器

I have database.yml and database_nba.yml which holds access to the second SQL server and cannot get it to work with two concurrent database servers. 我有database.ymldatabase_nba.yml ,它们可以访问第二台SQL服务器,但无法使其与两个并发数据库服务器一起使用。

You have to specify the different databases in your database.yml 您必须在database.yml中指定其他数据库

production:
  adapter:mysql, :other_adapter, :other_adapter

https://www.rubydoc.info/docs/rails/4.1.7/ActiveRecord/ConnectionAdapters https://www.rubydoc.info/docs/rails/4.1.7/ActiveRecord/ConnectionAdapters

Check the above docs. 检查以上文档。

In order to access different databases at the same time you have to create models specific to those databases. 为了同时访问不同的数据库,您必须创建特定于那些数据库的模型。 Once you do that, depending on the object you create it talks to the appropriate backend database. 完成此操作后,根据您创建的对象,它会与相应的后端数据库对话。

https://www.google.com/amp/s/www.thegreatcodeadventure.com/managing-multiple-databases-in-a-single-rails-application/amp/ https://www.google.com/amp/s/www.thegreatcodeadventure.com/managing-multiple-databases-in-a-single-rails-application/amp/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM