0
我在database.yml文件不能轉儲遠程數據庫
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: oma_development
pool: 5
username: root
password:
host: localhost
test:
# same as in development section
production:
# same as in development section
development_blacklist:
adapter: mysql2
encoding: utf8
database: webstuff
username: login
password: password
host: remote-database.com
test_blacklist:
adapter: mysql2
encoding: utf8
database: webstuff
username: megas
password:
host: /var/run/mysqld/mysqld.sock
此數據庫配置,我想執行的rake任務:
namespace :db do
namespace :schema do
desc 'Dump blacklist database schema'
task :dump => [:environment, :load_config] do
filename = "#{Rails.root}/db/blacklist_schema.rb"
File.open(filename, 'w:utf-8') do |file|
ActiveRecord::Base.establish_connection("development_blacklist")
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
end
end
end
通過調用該命令:
rake db:schema:dump
而且我有錯誤:
rake aborted!
Access denied for user 'root'@'localhost' (using password: NO)
所以看起來rake任務試圖從development
部分連接到數據庫。
我不明白爲什麼rake任務試圖連接到development
數據庫,而rake任務應該連接到development_blacklist
數據庫。
如何設置rake任務只連接到development_blacklist
數據庫?
或'RAILS_ENV = development_blacklist耙分貝:模式:dump'你的情況 – 2013-03-15 11:33:45