mysqlruby-on-railsdevelopment-environmentproduction-environmentpg

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.
Locally I use mysql2 and I need to use the data there when running locally.

I thought I could just temporarily remove the pg reference in the Gemfile production group and use mysql instead, i.e.

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. 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.

My Gemfile lists mysql2 as a dependency and not pg

How can I get the server running locally in production mode against my mysql database ?


Solution

  • Have you changed the production node in your database.yml to use mysql2 adapter?

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