Rails 4 - 如何在开发中使用sqlite3和在Heroku中使用PostgreSQL [英] Rails 4 - how to use sqlite3 in development and PostgreSQL in production w/Heroku

查看:94
本文介绍了Rails 4 - 如何在开发中使用sqlite3和在Heroku中使用PostgreSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图部署到Heroku,但不能,因为默认的sqlite3服务器仍然存在。


检测到Heroku不支持的sqlite3 gem。
https://devcenter.heroku.com/articles/sqlite3


在Rails 3.2.13的另一个教程中,我能够使用sqlite3作为开发数据库和Postgres作为生产数据库。 Gemfile在Rails 4中看起来有所不同,但我已经修改了它:

  group:development do 
#使用sqlite3作为Active Record的数据库
gem'sqlite3'
end

group:production do
gem'pg'
end

然后,我更改了我的database.yml文件,以便生产部分看起来像这样:

 生产:
适配器:postgresql
数据库:my_production_database
池:5
超时:5000

然后运行 bundle install rake db:create rake db:migrate 但我仍然无法推送到Heroku。所以我尝试了 rake db:drop 以及 rake db:create rake db:迁移但我仍然收到相同的错误消息。



我错过了什么吗?我还需要做些什么来确保将Postgres作为我的生产数据库并能够使用Heroku? 解决方案

不要这样做。你只会在路上遇到问题。在生产和开发中使用相同的数据库。在记录从sqlite到postgres数据库的切换时有很多可用的资源。



花点时间和切换。



看看这个Rails Cast。



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


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?

解决方案

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

这篇关于Rails 4 - 如何在开发中使用sqlite3和在Heroku中使用PostgreSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆