繁体   English   中英

Heroku或Rails如何配置数据库?

[英]How Heroku or Rails config a database?

我是Rails的新手。 我将我的玩具应用程序从cloud9推到了Heroku,尽管我的Heroku应用程序中来自Heroku工具带的database.yml如下所示,但我的Heroku应用程序正在使用PostgreSQL:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

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

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

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

我知道它使用的是PostgreSQL,因为我可以使用pgAdmin III远程访问数据库。

那么Heroku内部发生了什么?

Heroku不允许使用SQLite。 它将使用PostgreSQL,并在您上传应用程序时自动为您创建一个。

SQLite并不是真正成为生产数据库。 由于SQLite在内存中运行,因此如果将它用作Heroku上的数据库,则每天将清除整个数据库一次。 有更多的信息在这里

实际上,我很惊讶您在部署时没有出现任何错误。 过去,当我不小心离开了SQLite时,总是会遇到“推送失败”的情况。 Heroku有一个非常好的教程 ,可以将您的数据库从SQLite更改为PostgreSQL。

使用Heroku时,Heroku服务器将注入自己的数据库yml文件(将使用数据库url)。 这就是为什么代码中的database.yml不起作用的原因。

您可以在这里阅读更多内容https://devcenter.heroku.com/articles/rails-database-connection-behavior

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM