rake db:create:all
を試して、はい、それはRailsアプリケーションで複数のDBコネクションを持つことが可能です。
これは私が一度行ったことですが、私はActiveRecord::Base
から継承し、これらのクラス内の接続を設定する2つのクラスを作成しました。
は、それから私は、代わりに以下の直接ActiveRecord
のこれらのクラスのいずれかにすべての私のモデルを継承した例である:
:その後、私は両方TEST1とTEST2のデータベースのための2つのモデルを持っている
database.yml file
#app uses two database
#1 - test1
#2 - test2
test1:
adapter: mysql
encoding: utf8
database: test1
username: root
password: xxx
host: localhost
test2:
adapter: mysql
encoding: utf8
database: test2
username: root
password: xxx
host: localhost
class Test1Base < ActiveRecord::Base
self.abstract_class = true
establish_connection("test1")
end
class Test2Base < ActiveRecord::Base
# No corresponding table in the DB.
self.abstract_class = true
establish_connection("test2")
end
私はデータベースに基づいてモデルを継承します:
class School < Test1Base
#code
end
class Student < Test2Base
#code
end
こんにちはsameera C
Shamith、あなたの答えは正しいです。私は "portal_development"のためのモデルを移行することができますか?もう1つの質問があります。私を助けてください... –
こんにちは@Shamith、オープス、それはタイプミスでした、それはenv名でなければなりません、上記のdatabase.ymlを編集しました。例として私の既存のファイルは、いくつかの行を削除するのを忘れて、ごめんなさい...:D – sameera207