Rails 4 - how to use sqlite3 in development and Po

2020-05-19 07:51发布

问题:

I am trying to deploy to Heroku but can't because the default sqlite3 server is still in place.

Detected sqlite3 gem which is not supported on Heroku. https://devcenter.heroku.com/articles/sqlite3

In another tutorial with Rails 3.2.13 I was able to use sqlite3 as the dev db and Postgres as the production db. The Gemfile looks different in Rails 4 but I have modified it to have this:

group :development do
  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end

I then changed my database.yml file so that the production section looked like this:

production:
  adapter: postgresql
  database: my_production_database
  pool: 5
  timeout: 5000

I then ran bundle install and rake db:create and rake db:migrate but am still unable to push to Heroku. So I tried rake db:drop as well as rake db:create and rake db:migrate but am still getting the same error message.

Am I missing something? What else do I need to do to make sure I'm getting Postgres as my production database and am able to use Heroku?

回答1:

Don't do it. You are just going to run into problems down the road. Use the same database in production and development. There are a lot of resources available in documenting the switch from a sqlite to postgres database.

Take the time and switch.

Have a look at this Rails Cast.

http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast



回答2:

Try using this for your production DB

production:
  adapter: postgresql
  host: localhost
  encoding: unicode
  database: my_production_database
  pool: 5
  username:
  password:

You can leave username and password blank