![](/img/trans.png)
[英]Connecting Java Application to Ruby on Rails SQLite3 Database
[英]could one ruby on rails application use two sqlite3 database?
在我的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
在我的模型中,我通过以下方式调用新数据库establish_connection :otherdb
但这会返回错误, database configuration does not specify adapter
那么sqlite3不能一次使用2 db的问题吗?
如果是这样,我该如何解决。
是的,当然可以,但是在每个模型中,您都应该定义要使用的数据库。 您可以使用方法Establishment_connection定义哪个数据库应使用当前模型。 更多信息,请参见http://api.rubyonrails.org/classes/ActiveRecord/Base.html 。 但是我建议您创建几个基本的活动记录类,以在每个类中定义数据库名称,然后从它们中继承模型类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.