gpt4 book ai didi

ruby-on-rails - 使用 Heroku 多个环境时无效的 DATABASE_URL

转载 作者:行者123 更新时间:2023-12-04 06:35:49 25 4
gpt4 key购买 nike

我正在尝试从 Heroku 完成本教程。

http://devcenter.heroku.com/articles/multiple-environments

但是,当我尝试执行此命令时:

heroku rake db:migrate --remote staging

我收到这个错误:

rake aborted!
Invalid DATABASE_URL

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

与 --trace:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
rake aborted!
Invalid DATABASE_URL
(erb):9:in `rescue in <main>'
(erb):6:in `<main>'
/usr/ruby1.9.2/lib/ruby/1.9.1/erb.rb:753:in `eval'
/usr/ruby1.9.2/lib/ruby/1.9.1/erb.rb:753:in `result'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.1.3/lib/rails/application/configuration.rb:106:in `database_configuration'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/railtie.rb:68:in `block (2 levels) in <class:Railtie>'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:42:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/base.rb:2190:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/railties/databases.rake:6:in `block (2 levels) in <top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/bin/rake:19:in `load'
/app/.bundle/gems/ruby/1.9.1/bin/rake:19:in `<main>'
Tasks: TOP => db:migrate => db:load_config

有没有人有类似的经历?非常感谢。

最佳答案

遇到了同样的问题,终于解决了。以下是我用来实现此功能的步骤:

  1. 键入 heroku config --remote REMOTE_NAME(或 --app APP_NAME)。请注意,DATABASE_URL 未设置。
  2. 对于未设置 DATABASE_URL 的应用程序,通过键入 heroku addons:add heroku-postgresql:dev --remote REMOTE_NAME 添加 Postgres 数据库插件
  3. 通过键入 heroku pg:promote DB_NAME_FROM_STEP_2 --remote REMOTE_NAME 使新添加的 Postgres 数据库成为应用程序的默认数据库,其中 DB_NAME_FROM_STEP_2 的格式为 HEROKU_POSTGRESQL_COLOR_URL(颜色类似于红色或灰色)

就是这样!不要忘记在推送之后执行 heroku run rake db:migrate --remote REMOTE_NAME 以迁移 Heroku 数据库。

引用资料:

关于ruby-on-rails - 使用 Heroku 多个环境时无效的 DATABASE_URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8789897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com