Heroku on Rails - DATABASE_URL 无效

2024-02-05

编辑:一般建议是使用CEDAR stack.

对于 RoR、Gems、Heroku 和 Git 来说还很陌生。以下教程:http://ruby.railstutorial.org/book/ruby-on-rails-tutorial http://ruby.railstutorial.org/book/ruby-on-rails-tutorial

当部署到 Heroku 时,可以在 localhost 上顺利运行连接未建立错误,这里解决了:https://stackoverflow.com/questions/7542745/heroku-error-activerecordconnectionnotbuilted https://stackoverflow.com/questions/7542745/heroku-error-activerecordconnectionnotestablished (顺便说一句:遵循相同的教程)将生产数据库更改为 PostgreSQL 后(宝石'pg')它会产生另一个错误:

访问现场

应用程序发生错误,您的页面无法显示 服务。请稍后重试。

如果您是应用程序所有者,请检查您的日志以了解详细信息。

尝试过这个 -Heroku 应用程序崩溃,在尝试 heroku rake db:migrate 时收到“无效的数据库 URL” https://stackoverflow.com/questions/6335910/heroku-app-crashed-receiving-invalid-database-url-when-attempting-heroku-rake - heroku rake 数据库:迁移

rake aborted!
Invalid DATABASE_URL

Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)

赫罗库控制台

Internal server error

gemfile

source 'http://rubygems.org'

gem 'rails', '3.1.1'

group :development do
  gem 'rspec-rails', '2.6.1'
  gem 'annotate', '~> 2.4.1.beta' 
  gem 'sqlite3'
end

group :test do
  gem 'rspec-rails', '2.6.1'
  gem 'webrat', '0.7.1'
  gem 'sqlite3'
end

group :production do
    gem 'pg'
end

group :assets do
  gem 'sass-rails',   '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

赫罗库日志

9:02+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:143:in `run!'
9:02+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/bin/thin:6:in `<top (required)>'
9:02+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:177:in `run_command'
9:02+00:00 app[web.1]:   from /home/heroku_rack/heroku.ru:18:in `block (2 levels) in <main>'
9:02+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize'
9:02+00:00 app[web.1]:   from /usr/ruby1.9.2/bin/thin:19:in `<main>'
9:02+00:00 app[web.1]:   from /usr/ruby1.9.2/bin/thin:19:in `load'
9:03+00:00 heroku[web.1]: State changed from starting to crashed
9:04+00:00 heroku[web.1]: Process exited
1:58+00:00 heroku[slugc]: Slug compilation started
3:09+00:00 heroku[api]: Deploy 3dea426 by [email protected] /cdn-cgi/l/email-protection
3:09+00:00 heroku[api]: Release v7 created by [email protected] /cdn-cgi/l/email-protection
3:09+00:00 heroku[web.1]: State changed from crashed to created
3:09+00:00 heroku[web.1]: State changed from created to starting
3:10+00:00 heroku[slugc]: Slug compilation finished
3:12+00:00 heroku[web.1]: Starting process with command `thin -p 44881 -e production -R /home/heroku_rack/heroku.ru start`
3:15+00:00 app[web.1]: (erb):9:in `rescue in <main>': Invalid DATABASE_URL (RuntimeError)
3:15+00:00 app[web.1]:   from (erb):6:in `<main>'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/1.9.1/erb.rb:753:in `eval'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/1.9.1/erb.rb:753:in `result'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/application/configuration.rb:106:in `database_configuration'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/railtie.rb:68:in `block (2 levels) in <class:Railtie>'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `each'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:2190:in `<top (required)>'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `block in require'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:225:in `load_dependency'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:489:in `load_missing_constant'
3:15+00:00 app[web.1]:   from /app/app/models/user.rb:12:in `<top (required)>'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `each'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `const_missing'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:124:in `block in constantize'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:123:in `each'
3:15+00:00 a
 from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:123:in `constantize'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/core_ext/string/inflections.rb:43:in `constantize'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:348:in `require_or_load'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:181:in `block in const_missing'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/params_wrapper.rb:148:in `_default_wrap_model'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/params_wrapper.rb:167:in `_set_wrapper_defaults'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/params_wrapper.rb:128:in `inherited'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/railties/routes_helpers.rb:7:in `block (2 levels) in wi

3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.1.1/lib/action_controller/railties/paths.rb:7:in `block (2 levels) in with'
3:15+00:00 app[web.1]:   from /app/app/controllers/users_controller.rb:1:in `<top (required)>'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `block in require'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:225:in `load_dependency'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:348:in `require_or_load'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:302:in `depend_on'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:214:in `require_dependency'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:417:in `block (2 levels) in eager_load!'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:416:in `each'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:416:in `block in eager_load!'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:414:in `each'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:414:in `eager_load!'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/application/finisher.rb:51:in `block in <module:Finisher>'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `instance_exec'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `run'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `each'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `run_initializers'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/application.rb:96:in `initialize!'
3:15+00:00 app[web.1]:   from /app/config/environment.rb:5:in `<top (required)>'
3:15+00:00 app[web.1]:   from <internal:lib/rubygems/custom_require>:29:in `require'
3:15+00:00 app[web.1]:   from <internal:lib/rubygems/custom_require>:29:in `require'
3:15+00:00 app[web.1]:   from config.ru:3:in `block (3 levels) in <main>'
3:15+00:00 app[web.1]:   from /home/heroku_rack/heroku.ru:23:in `eval'
3:15+00:00 app[web.1]:   from /home/heroku_rack/heroku.ru:23:in `block (3 levels) in <main>'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:120:in `new'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:120:in `map'
3:15+00:00 app[web.1]:   from /home/heroku_rack/heroku.ru:18:in `block (2 levels) in <main>'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize'
3:15+00:00 app[web.1]:   from /home/heroku_rack/heroku.ru:11:in `new'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize'
3:15+00:00 app[web.1]:   from /home/heroku_rack/heroku.ru:11:in `block in <main>'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval'
3:15+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize'
3:15+00:00 app[web.1]:   from /home/heroku_rack/heroku.ru:1:in `new'
3:15+00:00 app[web.1]:   from /home/heroku_rack/heroku.ru:1:in `<main>'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/rack/adapter/loader.rb:36:in `eval'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/rack/adapter/loader.rb:36:in `load'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/controllers/controller.rb:175:in `load_rackup_config'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/controllers/controller.rb:65:in `start'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:143:in `run!'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/bin/thin:6:in `<top (required)>'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/bin/thin:19:in `load'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/bin/thin:19:in `<main>'
3:15+00:00 app[web.1]:   from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/thin-1.2.6/lib/thin/runner.rb:177:in `run_command'
3:16+00:00 heroku[web.1]: State changed from starting to crashed
3:17+00:00 heroku[web.1]: Process exited
5:55+00:00 heroku[router]: Error H10 (App crashed) -> GET high-wind-7473.heroku.com/pages/home dyno= queue= wait= service= status=503 bytes=
5:57+00:00 heroku[router]: Error H10 (App crashed) -> GET high-wind-7473.heroku.com/pages/home dyno= queue= wait= service= status=503 bytes=

有点卡住了,请帮忙(指出正确的方向)

当然

bundle install
git add .
git commit -m "another heroku fix"
git push
git push heroku

您需要设置DATABASE_URL环境变量,其中包含在线 postgres 数据库的路径。

尝试跑步heroku pg。如果输出是“myapp没有heroku-postgresql数据库”。那么你需要先添加 PostgreSQL 插件。它将在 Amazon AWS 上为您创建一个 postgres 数据库。

heroku addons:add heroku-postgresql:hobby-basic

(爱好基本是免费计划)

要查找新数据库的 URL,请运行

heroku config

您应该看到一个以以下开头的变量HEROKU_POSTGRESQL。复制它的值(它应该以postgres://并用它来设置DATABASE_URL

heroku config:set DATABASE_URL=postgres://your-db-url
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Heroku on Rails - DATABASE_URL 无效 的相关文章

  • Ruby:如何编写 gem? [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我想为 Ruby 编写一个包并将其作为 gem 提供 有哪些工具 步骤和陷阱 有没有好的教程 截屏视频等
  • 更新系统后RubyGems错误

    使用 sudo gem update system 更新 ruby 设置后尝试启动 Rails 控制台时 我尝试通过发出以下命令来执行 Rails 控制台rails c 我收到此错误 Users myusername rvm rubies
  • 装饰 Rails 中的属性

    我有一个name上的属性Person模型 每次我访问name属性 我想要name capitalize被退回 在模型内执行以下操作将不起作用 def name name capitalize end 那么还有什么选择呢 我建议您使用自定义格
  • 如何从 Rails 项目中删除 gem?

    我正在尝试从我的项目中删除一个 gem 因此我进入了 gem 文件并将其注释掉 gem some gem gem gem I dont want gem another gem 然后我跑 bundle 为了检查宝石是否消失 我输入 bund
  • 如何使用 RSpec 测试 javascript 重定向?

    我正在使用 xhr post 与控制器交互 并且我期待重定向 在 js erb 中 我有 window location href address 手动测试 浏览器会正确重定向 我如何使用 RSpec 测试它 response should
  • 如何验证单选按钮?

    我的 Rails 应用程序中有一个单选按钮 我想编写一个 java 脚本代码 在未选择任何选项时验证这一点 在你的 votes 类中做类似的事情 class Myvotes lt ActiveRecord Base validates vo
  • 使用 Symfony 3 / Doctrine 进行属性形式的一对多对一

    问题是这样的 我有一个包含 3 个类的模型 person 人员 工作 job 一个人可以有多个工作 任何工作与人的关系都可以有 date start 属性 date end 和 comment 因此 我使用持有这些属性的可连接 person
  • 可以通过 url 发送 JSON 吗?

    我有一个 ruby 哈希 其中键是 url 值是整数 我将哈希值转换为 JSON 我想知道是否能够通过 AJAX 请求在 url 内发送 JSON 然后从 params 哈希值中提取该 JSON 另外 我将把 JSON 化的 ruby 哈希
  • Rails“where”方法通过子属性查找父级

    我有一个 Rails 应用程序 我试图根据子类的日期创建父类的列表 现在我有 orders Order where order reminders date lt 1 month from now 但我收到一个错误 没有这样的列 order
  • jRails 是 Rails + jQuery 必须的吗?

    我是rails新手 使用rails 2 3 10 并且想使用jquery 特别是jquery ui 该项目是一个全新的项目 我计划使用 jquery ui 中的一些小部件 如 datapicker 和 selectable 等 我听说可以安
  • 如何获得组中“中间”值的平均值?

    我有一个包含值和组 ID 的表 简化示例 我需要获取中间 3 个值的每组的平均值 因此 如果有 1 2 或 3 个值 则它只是平均值 但如果有 4 个值 它将排除最高值 5 个值将排除最高值和最低值 等等 我正在考虑某种窗口函数 但我不确定
  • 如何编写不返回任何内容的 postgres 存储过程?

    如何在 postgres 中编写一个根本不返回值的简单存储过程 即使使用 void 返回类型 当我调用存储过程时 我也会返回一行 CREATE FUNCTION somefunc in id bigint RETURNS void AS B
  • 如何插入UUID的值?

    我在 Play Framework 2 3 支持的 postgresql 9 4 中使用 anorm 2 4 给出一个这样的模型 case class EmailQueue id UUID send from String send to
  • 配置 PostgreSQL 仅适用于 LOCALHOST 或指定的 ip + 端口 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我想将 PostgreSQL 配置为仅接受来自指定 IP 的连接 它不应接受来自任何其他 IP 的请求 以下示例 pg hba conf
  • 从 Ruby on Rails 3.2.6 中的 Paperclip 生成的文件中删除问号

    我正在使用 Paperclip FFMPEG 将视频文件上传到我的开发环境 并最终在我的项目投入生产时上传到本地服务器 视频上传时 默认文件名如下 system modelnames paperclipnames mynewfile mp4
  • 如何在 Postgresql 中将 GIST 或 GIN 索引与 hstore 列一起使用?

    我正在使用 postgresql 9 3 的 hstore 我正在尝试对 hstore 列使用索引就像文档所述 http www postgresql org docs 9 3 static hstore html 我的问题是索引似乎没有被
  • 如何监听第三方应用程序触发的数据库更改

    我需要将 Ruby on Rails 应用程序与第 3 方应用程序集成 该应用程序将共享一个公共 PostgreSQL 数据库 也就是说 Rails 应用程序和第 3 方应用程序将使用相同的 PG 数据库 是否可以在 Rails 应用程序中
  • sql直接获取表行数的方法

    stackoverflow 的朋友们大家好 我的例行程序中有一个我认为不必要的步骤 假设您想从图库中获取所有图像 并限制每页一定数量的图像 db PDO object start pagenum x images per page limi
  • 查找日期时间与今天日期匹配的记录 - Ruby on Rails

    我有一个交易表 需要查找日期与今天的日期匹配的记录 从 Rails 控制台 我需要匹配的日期字段如下所示 我已经分配了一条记录来进行测试 ruby 1 9 2 p0 gt deal start gt Tue 10 May 2011 00 0
  • 从使用heroku发送的邮件中删除“via sendgrid.me”

    我正在使用免费的 sendgrid 计划从 Heroku 上托管的 Rails 应用程序发送电子邮件 我使用以下组合进行设置这些说明 http devcenter heroku com articles sendgrid and 本教程 h

随机推荐