Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 一个RubyonRails应用程序可以使用两个sqlite3数据库吗?_Ruby On Rails_Database_Sqlite - Fatal编程技术网

Ruby on rails 一个RubyonRails应用程序可以使用两个sqlite3数据库吗?

Ruby on rails 一个RubyonRails应用程序可以使用两个sqlite3数据库吗?,ruby-on-rails,database,sqlite,Ruby On Rails,Database,Sqlite,在我的config/database.yml文件中 # SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 # Warning:

在我的config/database.yml文件中

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

otherdb:
  adapter: sqlite3
  database: /c/Users/dsun/Documents/apeers/db/development.sqlite3
  pool: 5
  timeout: 10000
在我的模型中,我通过以下方式调用新数据库:
build\u connection:otherdb

但这会返回一个错误,
数据库配置未指定适配器

那么sqlite3不能一次使用2 db的问题是什么呢


如果是这样,我该如何解决这个问题。

当然可以,但在每个模型中,您都应该定义要使用的wich数据库。 您可以使用方法“建立\ U连接”来定义哪个数据库应该使用当前模型。
这里有更多。但是我可以建议创建几个基本活动记录类来定义每个模型中的数据库名称,然后从中继承模型类。

当然可以,但是在每个模型中,您应该定义要使用的数据库。 您可以使用方法“建立\ U连接”来定义哪个数据库应该使用当前模型。
这里有更多。但我建议创建几个基本活动记录类来定义每个类中的数据库名称,然后从它们继承模型类。

看看这个问题:您试图找到解决方案的根本原因是什么?看看这个问题:您试图找到解决方案的根本原因是什么?非常感谢!我已修复此问题~原始路由位于我的应用程序的路由下,因此我使用此“./”返回我的应用程序外部,并查找外部db。我为外部数据库创建了一个父模型,让我的模型按照您的建议继承,现在可以工作了!非常感谢你!我已修复此问题~原始路由位于我的应用程序的路由下,因此我使用此“./”返回我的应用程序外部,并查找外部db。我为外部数据库创建了一个父模型,让我的模型按照您的建议继承,现在可以工作了!