【问题标题】:Heroku postgres no longer overwrites config/database.yml Rails 4.1.4 (and other questions)Heroku postgres 不再覆盖 config/database.yml Rails 4.1.4(和其他问题)
【发布时间】:2015-01-14 22:00:53
【问题描述】:

我对 RoR 非常陌生,我无法理解如何正确设置 Heroku Postgres 并将其与我的 Rails 4.1.4 应用程序一起使用。我在 Ubuntu 14.04.1 LTS 上。

我想要本地 PostgreSQL 数据库用于开发和测试,以及 Heroku Postgres 数据库用于生产。

这是我到目前为止所达到的:

  • 我按照heroku官方文档here设置PostgreSQL
  • 我安装了pg gem
  • 我更改了我的config/database.yml 文件:

    default: &default
      adapter: postgresql
      encoding: unicode
      pool: 5
      timeout: 5000
      username: franklin
      password:
    
    development:
      <<: *default
      database: myapp_development
    
    test:
      <<: *default
      database: myapp_test
    
    production:
      url: <%= ENV["DATABASE_URL"] %>
    

    我从 here 得知 Heroku 不再覆盖 Rails 4.1.x 应用程序的 config/database.yml,我应该(必须?)在生产条目中指定 DATABASE_URL。

  • 我运行 rake db:create:all 创建本地开发和测试数据库,然后运行 ​​rake db:migrate

  • 我 git commit 更改,然后使用 git push heroku master 将我的应用推送到 Heroku
  • 我运行 heroku run rake db:migrate 并收到以下消息:Running rake db:migrate attached to terminal... up, run.1227(我不确定这是什么意思?)
  • 我终于跑了heroku restart

然后,当我连接到我的开发数据库时,我可以看到由rake db:migrate 命令创建的新表,以及我通过在 localhost:3000 中运行我的应用程序特意创建的新数据(表单提交)。我得到了完全预期的行为。

但是当我连接到我的 Heroku Postgres 生产数据库时,应该由 heroku run rake db:migrate 命令创建的新表不存在。当我将数据添加到不存在的表(表单提交)时,我的 Heroku 应用程序不会崩溃。

这是我的问题:

  1. 我的生产条目是否在config/database.yml 中正确配置?
  2. 如何正确迁移到 Heroku Postgres 生产数据库?
  3. 如果我的 Heroku 应用程序中的数据不在表格中,它会去哪里?

任何帮助将不胜感激!谢谢!

【问题讨论】:

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


【解决方案1】:

你需要去https://postgres.heroku.com/databases

在那里找到您的应用程序的数据库,您将找到适合您的数据库的键。您可以将这些作为配置变量上传并加载到您的database.yml

查看figaro 以获得更简单的方法来处理您的配置变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-07
    • 2012-09-14
    • 2016-08-26
    • 2011-05-11
    • 2011-06-19
    • 2012-10-04
    • 2019-08-15
    • 1970-01-01
    相关资源
    最近更新 更多