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 无效 的相关文章

  • 添加两个 ActiveRecord::Relation 对象[重复]

    这个问题在这里已经有答案了 如何将两个关系添加在一起 当我尝试 运算符时 它返回一个数组 但我需要它来返回关系 谢谢 麦克风 Try new relation relation merge another relation
  • Rails 如何使用 send_data 导出数据,然后重定向到新页面?

    我有一个 Rails 应用程序 允许用户下载生成的 CSV 文件 下载文件后 我想将用户重定向到新的 URL 或操作 有没有在 send data 之后进行重定向的技巧 我想做这样的事情 这不起作用 send data output typ
  • 提高第一个查询的性能

    如果执行以下数据库 postgres 查询 则第二次调用要快得多 我猜第一个查询很慢 因为操作系统 linux 需要从磁盘获取数据 第二个查询受益于文件系统级别和 postgres 中的缓存 有没有一种方法可以优化数据库以快速获得结果fir
  • 更改 Active Storage 的默认 URL

    我们可以更改从活动存储创建的默认 永久 url 以重定向到 S3 类似于rails active storage representations 我不喜欢网址中的框架名称 Thanks UPDATE 最近 Rails 6 中增加了一个可配置
  • <%=h ... %> 在 Rails 中意味着什么?

    I found here http api rubyonrails org classes ActionView Helpers RecordTagHelper html以下语法 什么是h means 它用于转义标签的输出以避免跨站点脚本
  • Rails HABTM 设置、模型对象和 join_table 插入控制器设置

    我有以下设置 1 个产品有多个 Product types 许多 Product types 有 1 种类型 根据我对文档的理解 HABTM 关系 我的模型是 class Product lt ApplicationRecord has a
  • 如何检查字符串是否为有效日期

    我有一个字符串 31 02 2010 并想检查它是否是有效日期 最好的方法是什么 我需要一个方法 如果字符串是有效日期 则返回 true 如果不是 则返回 false require date begin Date parse 31 02
  • SQL 约束以防止根据列的先前值更新列

    是否可以使用检查约束 或其他一些技术 来防止在更新记录时设置与其先前值相矛盾的值 一个例子是 NULL 时间戳 表明发生了某些事情 例如 file exported 一旦文件被导出并且具有非 NULL 值 就不应再将其设置为 NULL 另一
  • 转义 to_tsquery 中的特殊字符

    如何转义传递给的字符串中的特殊字符to tsquery 例如 这种查询 select to tsquery AT T 生产 NOTICE text search query contains only stop words or doesn
  • “heroku”命令存在于以下 Ruby 版本中:

    我在使用 heroku 工具带时遇到了重大问题 我正在使用 cedar 14 堆栈 当我尝试使用不是的 ruby 版本时ruby 2 0 0 dev我收到这个错误 rbenv heroku command not found The her
  • Heroku 没有更新 Rails 应用程序的 CSS

    我在 heroku 上更新 Rails 应用程序时遇到问题 我已经启动了我的应用程序 但我尝试更改 public stylesheets 中的 application css 文件 但每当我尝试推送到 heroku 时 CSS 都不会更改
  • MySQL 与 PostgreSQL JSON 搜索功能

    我一直在寻找一篇博客文章或一个功能矩阵 通过 JSON 功能对 MySQL 和 PostgreSQL 进行比较 我找到了一个好的Postgres 的特征矩阵 https www postgresql org about featuremat
  • 加载“mysql2”Active Record 适配器时出错

    我正在尝试升级我的应用程序 这是我在部署应用程序时遇到的错误 加载 mysql2 Active Record 适配器时出错 缺少它所依赖的宝石 无法激活mysql2 0 4 4 已经激活mysql2 0 3 21 确保所有依赖项都添加到 G
  • 使用 Ruby 重命名 S3 中的对象

    我想使用 Ruby sdk 重命名 s3 中的项目 我该怎么做呢 我努力了 require aws sdk s3 AWS config region gt region access key id gt key secret access
  • Docker 容器在运行或重新启动 PostgreSQL 镜像后立即退出

    我是 docker 的初学者 由于容器重新启动问题 我陷入困境 当我尝试重新启动现有退出的容器或创建新容器 删除旧容器后 运行时 会出现问题 docker run d name mempostgres v home lukasz lc pg
  • 具有委托和条件的 Active Record

    是否可以在 Active Record 模型中使用委托并使用诸如 if on it class User lt ApplicationRecord delegate company to gt master if gt has master
  • Heroku 上的 Rails 4 应用程序中未初始化的常量 Moped::BSON

    我刚刚从rails 3更新到rails 4 一切都在本地运行 但部署在heroku上 出现以下错误 ActionView Template Error uninitialized constant Moped BSON 3 nav navb
  • Heroku 多个 dyno socket.io

    我正在使用 Socket io 开发一个 node js 应用程序 并将其部署在 Heroku Dyno 上 Socket io 使用 RedisStore 及其 PUB SUB Socket io 客户端与 Heroku 中的一个 dyn
  • 添加多态引用的向下迁移是什么

    我有以下迁移 但不知道在其中使用什么down method change table addresses do t t references addressable polymorphic gt true end 实际上 change ta
  • 错误:运算符不存在:整数 = 字符变化,使用 Postgres 8.2

    我有一个用旧版本的 Eclipse Ganymede 如果我没记错的话 开发的 Java EE Web 应用程序 我最近迁移到 Kubuntu 12 04 LTS 并将应用程序迁移到 Eclipse Kepler 我从 Eclipse 网站

随机推荐