简体   繁体   中英

could one ruby on rails application use two sqlite3 database?

in my config/database.yml file

# 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

and in my model, I call the new database via: establish_connection :otherdb

but this returns an error, database configuration does not specify adapter

so is it the problem that sqlite3 can not use 2 db in one time?

if so, how can I fix this.

Yes, of course, but in each model you should define wich database to use. You can use method establish_connection to define which database should use current model. More here http://api.rubyonrails.org/classes/ActiveRecord/Base.html . But I can recommend to create several base active record classes to define the database name in each, and then just inherit your model classes from them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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