简体   繁体   English

rails - 如何在生产模式下针对开发数据库运行?

[英]rails - how to run in production mode against the development database?

I'm in the process of updating an app to use asset compilation.我正在更新应用程序以使用资产编译。

I want to try running the server locally in production mode so I do我想尝试在生产模式下在本地运行服务器,所以我这样做

RAILS_ENV=production rails server

and it tries to start up in production mode:并尝试以生产模式启动:

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

but aborts with但中止

=> 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)

as I have to use postgres in production for a Heroku deploy.因为我必须在生产环境中使用 postgres 进行 Heroku 部署。
Locally I use mysql2 and I need to use the data there when running locally.在本地我使用 mysql2 并且在本地运行时我需要使用那里的数据。

I thought I could just temporarily remove the pg reference in the Gemfile production group and use mysql instead, ie我想我可以暂时删除Gemfile生产组中的pg引用并使用mysql代替,即

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

and I did a bundle install but I still get the pg adapter error - even though I don't have it in my Gemfile and I've bundled.并且我进行了捆绑安装,但我仍然收到 pg 适配器错误 - 即使我的 Gemfile 中没有它并且我已经捆绑了。 There's only 1 Gemfile.lock so I assume I don't need to do RAILS_ENV=production bundle , though of course I tried it - it didn't help.只有 1 个 Gemfile.lock 所以我假设我不需要做RAILS_ENV=production bundle ,当然我试过了 - 它没有帮助。

My Gemfile lists mysql2 as a dependency and not pg我的 Gemfile 将 mysql2 列为依赖项而不是 pg

How can I get the server running locally in production mode against my mysql database?如何让服务器在生产模式下针对我的 mysql 数据库在本地运行?

Have you changed the production node in your database.yml to use mysql2 adapter? 您是否已将database.yml的生产节点更改为使用mysql2适配器?

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

in Gemfile在 Gemfile 中

group :production, :staging do
  gem 'mysql2'
end

In config/database.yml在配置/数据库.yml

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据库从开发迁移到生产-Rails - migrating database from development to production - rails 如何同步开发和生产数据库 - How to synchronize development and production database 生产模式下的Rails问题,mysql数据库 - Rails problem in production mode, mysql database Rails,如何将数据从开发sqlite3数据库迁移到生产MySQL数据库? - Rails, how to migrate data from development sqlite3 database to production MySQL database? 如何从开发数据库导入生产数据? - How to import Production Data from Development Database? 如何在开发和生产上使用不同的数据库 - How to use different database on development than production Rails .where对数据库的调用显示开发中的图像(mysql),但不显示生产中的图像(postgres) - Rails .where call to database shows images in development (mysql), but not production (postgres) 开发和生产数据库? - Development and Production Database? 如何仅将 Mysql 数据库结构从开发服务器复制到生产服务器(生产服务器有数据,而开发服务器没有) - How to copy only Mysql database structure from development to production server (production server have data, and development server no ) Rails 3:如何解决开发和生产环境中日期格式的不一致? - Rails 3: How to solve an inconsistency in date format in development and production environments?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM