如何在配置中指定数据库?

时间:2015-07-10 12:56:01

标签: ruby-on-rails ruby-on-rails-4

请帮助解决问题。

我创建了一个网站。我用的是sqlite3。 database.yml的:

default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

的Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.2.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bootstrap-sass', '3.2.0.0'
gem 'bcrypt', '~> 3.1.7'
gem 'populate'
gem 'faker'
gem 'russian', '~> 0.6.0'
gem 'will_paginate'
gem 'paperclip'
gem 'fancybox2-rails', '~> 0.2.8'
gem 'rspec-rails'
gem 'factory_girl'
gem 'database_cleaner'

group :development do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

在正在运行的本地服务器上。我把它上传到了heroku。收到以下错误消息的结果:

  

500内部服务器错误

heroku使用postgresql。那就是问题所在。请帮忙设置配置

1 个答案:

答案 0 :(得分:0)

正如它所说:你需要添加pg gem。在Gemfile中包含以下行

gem 'pg', group: :production

您在 config / database.yml 文件中,可以编写以下代码并进行适当的修改:

development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  pool: 5
  username: myapp
  password: password1

test:
  adapter: postgresql
  encoding: unicode
  database: myapp_test
  pool: 5
  username: myapp
  password: password1

production:
  adapter: postgresql
  encoding: unicode
  database: myapp_prouduction
  pool: 5
  username: myapp
  password: password1