【问题标题】:How to add database to Heroku (ROR)如何将数据库添加到 Heroku (ROR)
【发布时间】:2014-07-29 19:47:21
【问题描述】:

我在 ROR 应用中有数据库。我应该执行哪些命令才能使我的数据库正常工作?我还在 Heroku 上上传了我的应用程序。但我想拥有数据库。 (postgresql)

   development:
      adapter: postgresql
      database: Nature
      host: localhost
      username: postgres
      password: -----
      encoding: utf8


    test:
      adapter: sqlite3
      database: db/test.sqlite3
      pool: 5
      timeout: 5000

    production:
      adapter: sqlite3
      database: db/production.sqlite3
      pool: 5
      timeout: 5000

【问题讨论】:

  • 对于初学者,您的生产数据库不能是sqlite,除非您的问题非常模糊。试试here
  • Heroku 在devcenter.heroku.com/articles/… 上解释得很好。我会建议你的本地开发人员使用 postgres 而不是 sqlite3

标签: ruby-on-rails


【解决方案1】:

您需要使用postgresql 作为heroku 中提到的数据库适配器。之后在你的 gemfile 中用 gem 'pg' 替换 gem 'sqlite' 并运行 bundle install

据我所知,heroku 不会将 database.yml 中提到的数据库设置用于生产,但是,您可以将生产数据库设置为:

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

将您更新的代码推送到 heroku,heroku 将在那里为您的应用创建数据库。

此外,您还可以pull/push database 从/到 heroku。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-26
    • 2012-06-08
    • 2016-06-21
    • 2014-03-15
    • 1970-01-01
    • 2021-01-03
    • 2013-01-08
    • 2014-11-30
    相关资源
    最近更新 更多