我的应用程序包含staging
和production
服务器。 staging
必须运行sqlite3数据库并production
运行mysql数据库,因为staging
无法安装mysql2
gem。
这是关于暂存的完整database.yml
:
staging:
adapter: sqlite3
database: db/staging.sqlite3
pool: 5
timeout: 5000
但是,Gemfile有两个宝石:mysql2
和sqlite3
并在部署时得到这个:
** [out :: example.org] rake aborted!
** [out :: example.org] Incorrect MySQL client library version! This gem was compiled for 5.6.21 but the client library is 5.1.61.
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/mysql2-0.3.16/lib/mysql2/mysql2.so
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/mysql2-0.3.16/lib/mysql2.rb:8
** [out :: example.org] /path/to/my/app/application1/releases/20150918175707/config/application.rb:13
** [out :: example.org] /path/to/my/app/application1/releases/20150918175707/Rakefile:5:in `require'
** [out :: example.org] /path/to/my/app/application1/releases/20150918175707/Rakefile:5
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `load'
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `load_rakefile'
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/rake-10.0.4/lib/rake/application.rb:589:in `raw_load_rakefile'
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/rake-10.0.4/lib/rake/application.rb:89:in `load_rakefile'
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/rake-10.0.4/lib/rake/application.rb:88:in `load_rakefile'
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/rake-10.0.4/lib/rake/application.rb:72:in `run'
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
** [out :: example.org] /path/to/my/app/.gem/ruby/1.8/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
当mysql
中只有sqlite3
时,Rails如何以及为何尝试使用database.yml
?
答案 0 :(得分:0)
您需要像这样更新您的Gemfile
group :staging do
gem 'sqlite3'
end
group :production do
gem 'mysql'
end
基本上你需要告诉你的Gemfile哪个gem用于哪个环境,如果你不为所有环境安装它们,即使你不在代码中使用它们。
在宝石文件中执行此操作
if File.dirname(__FILE__).to_s.include?('part_of_production_directory_path')
gem 'mysql'
else File.dirname(__FILE__).to_s.include?('part_of_staging_directory_path')
gem 'sqlite3'
end