【问题标题】:rails - how to run in production mode against the development database?rails - 如何在生产模式下针对开发数据库运行?
【发布时间】:2014-02-22 14:15:34
【问题描述】:

我正在更新应用以使用资产编译。

我想尝试以生产模式在本地运行服务器,所以我这样做了

RAILS_ENV=production rails server

它会尝试以生产模式启动:

=> Rails 3.1.8 application starting in production on http://0.0.0.0:3000

但使用

中止
=> Ctrl-C to shutdown server
Exiting
/home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish_connection':  
Please install the pg adapter: `gem install activerecord-pg-adapter` (cannot load such file -- active_record/connection_adapters/pg_adapter) (RuntimeError)

因为我必须在生产环境中使用 postgres 进行 Heroku 部署。
本地我使用mysql2,本地运行时需要使用那里的数据。

我想我可以暂时删除Gemfile 生产组中的pg 引用并改用mysql,即

group :production
#  gem "pg" # Used for Production for heroku.
  gem 'mysql2'
end

并且我进行了捆绑安装,但仍然收到 pg 适配器错误 - 即使我的 Gemfile 中没有它并且我已经捆绑。只有 1 个 Gemfile.lock,所以我认为我不需要这样做 RAILS_ENV=production bundle,虽然我当然尝试过 - 它没有帮助。

我的 Gemfile 将 mysql2 列为依赖项而不是 pg

如何让服务器在生产模式下针对我的 mysql 数据库在本地运行?

【问题讨论】:

    标签: mysql ruby-on-rails development-environment production-environment pg


    【解决方案1】:

    您是否已将 database.yml 中的生产节点更改为使用 mysql2 适配器?

    production:
        adapter: mysql2
        database: your_database
        host: 127.0.0.1
        username:
        password:
    

    【讨论】:

    • 我没有,改变它有帮助。不幸的是,我现在得到 - ... rescue in depend_on': No such file to load -- /home/durrantm/.../linker/app/assets/../config/environment (LoadError)。知道这是为什么吗?
    • 比较你的文件 config/environments/development.rb 和 ..production.rb,好像少了什么。
    • 顺便说一句,它看起来可能来自 config.ru,它有 require ::File.expand_path('../config/environment', __FILE__) 。注意 - 这是一个较旧的(最初是 rails 2)应用程序。
    • 将接受这个作为答案并将我的下一个问题作为一个单独的问题发布。
    猜你喜欢
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多