を使用して、Rails で別の DB への移行を実行しようとしていますestablish_connection
。移行ファイルには次のようなものがあります。
def change
ActiveRecord::Base.establish_connection("user_#{Rails.env}")
ActiveRecord::Base.initialize_schema_migrations_table
create_table "users", :force => true do |t|
t.string "email",
end
yml には、次の構成があります。
user_development:
adapter: postgresql
encoding: unicode
database: MyApp_user_development
pool: 5
host: localhost
username: xxx
password: xxx
また、ユーザー モデルを次のように定義しました。
class User < ActiveRecord::Base
establish_connection "user_#{Rails.env}"
[...]
end
現在、DB は存在しますが、実行するrake db:migrate
と次のエラーが発生します。
== CreateUserOnSeparateDb: migrating =========================================
rake aborted!
An error has occurred, this and all later migrations canceled:
connection is closed
何が起こっているのか分かりますか?
establish_connection
また、呼び出しをconnection
移行ファイルのメソッドに移動しようとしました。この場合、テーブルは移行時に作成されますが、同じエラーが発生し (他の移行で何らかの形で失敗します)、ちなみに schema_migrations テーブルは作成されません...
何か助けはありますか?