Rails 4 - 如何在开发中使用sqlite3和使用Heroku生成PostgreSQL

时间:2022-07-19 22:47:20

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

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

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

检测到Heroku不支持的sqlite3 gem。 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:

在另一个使用Rails 3.2.13的教程中,我能够使用sqlite3作为dev db和Postgres作为生产db。 Gemfile在Rails 4中看起来有所不同,但我已将其修改为具有以下内容:

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:

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

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.

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

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?

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

2 个解决方案

#1


18  

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.

不要这样做。你将在未来遇到问题。在生产和开发中使用相同的数据库。记录从sqlite到postgres数据库的交换机有很多资源可用。

Take the time and switch.

花点时间切换。

Have a look at this Rails Cast.

看看这个Rails Cast。

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

#2


0  

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

您可以将用户名和密码留空

#1


18  

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.

不要这样做。你将在未来遇到问题。在生产和开发中使用相同的数据库。记录从sqlite到postgres数据库的交换机有很多资源可用。

Take the time and switch.

花点时间切换。

Have a look at this Rails Cast.

看看这个Rails Cast。

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

#2


0  

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

您可以将用户名和密码留空