1

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.

2
  • Have a look at this question: stackoverflow.com/questions/10360705/… Commented Apr 4, 2013 at 19:40
  • What's the underlying reason that you are trying to find a solution for? Commented Apr 4, 2013 at 21:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! I have fixed this problem~ the original route is under my app's route, so I use this "../" to go back outside my app, and find the external db. I create a parent model for external db let my models to inherit as you recommended, it's working now!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.