部署 herokub 报数据库 url 无效的错误,该怎么解决呢?

shangchen · June 06, 2013 · Last by w7938940 replied at November 06, 2013 · 6400 hits

执行 heroku run rake db:migrate 失败,提示如下,请问该怎么解决,谢谢! )> at /app/Rakefile:7) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:load_config (first_time) ** Execute db:load_config rake aborted! Invalid DATABASE_URL (erb):9:in rescue in <main>' (erb):6:in' /usr/local/lib/ruby/1.9.1/erb.rb:753:in eval' /usr/local/lib/ruby/1.9.1/erb.rb:753:inresult'

贴 config/database.yml

#1 楼 @Rei development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000

Warning: The database defined as "test" will be erased and

re-generated from your development database when you run "rake".

Do not set this db to the same as development or production.

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

production: adapter: postgresql database: production pool: 5 timeout: 5000 [user@localhost config]$

heroku 不支持 sqlite 数据库。

#3 楼 @Rei 只是测试和开发模式下是 sqlite 啊,porduction 模式下是 postgresql

#4 楼 @shangchen 目测还要加连接参数,但是我没搜到文档,自己也没用过,所以不知道了。

#4 楼 @shangchen heroku 似乎会自动生成 production 环境的数据库配置,你把 database.yml 里的 production 数据库配置删了试试。- -。

@shangchen 你直接将 database.yml 从 git 的版本库剔除就好了,不要 push 到 heroku 上面去。

#9 楼 @shangchen 你试试在 heroku 上手工添加一个 postgresql 数据库,然后在数据库设置里选择生成适合 activemodel 的配置,再把这个配置写到你的 database.yml 里。

用 postgresQL 数据库 Using pg:transfer to Migrate Postgres Databases heroku pg:transfer -f 本机的数据库地址 -t heroku 的数据库地址

heroku 会直接忽视你的 database 配置文件的吧 重新 commit push 一下 再试试

#11 楼 @ghjcumt2008 麻烦详细解释一下你的命令呢 实在受不了啦,搞了好几天了,第一个部署的练习就一直没做成功,唉 谁帮帮我吧

http://nameless-savannah-7872.herokuapp.com/blog,主页是默认的rails欢迎页面,我没有动过的。这到底是哪的问题呢这就是这个地址,就算数据库没对,也应该能看到主页是吧?我是按示例做到个

heroku logs 贴出来看看

等下,我要重新启动虚拟机

我是按示例做到一个 blog,主页是默认的,操作过程中也只有 db:migrate 失败了,访问网址是不是还是应该能看到主页呢

@shangchen 直接打 heroku logs 应该能看到错误提示信息,没找到问题的话贴出来看看

太多了,麻烦高手帮忙分析一下阿,非常感谢 heroku logs: 2013-06-07T14:10:42.153871+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in method_missing' 2013-06-07T14:10:42.154336+00:00 app[web.1]: from script/rails:6:inrequire' 2013-06-07T14:10:42.153602+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:438:in each' 2013-06-07T14:10:42.153602+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:438:inblock in eager_load!' 2013-06-07T14:10:42.154336+00:00 app[web.1]: from script/rails:6:in <main>' 2013-06-07T14:10:43.322655+00:00 heroku[web.1]: Process exited with status 1 2013-06-07T14:10:43.340656+00:00 heroku[web.1]: State changed from starting to crashed 2013-06-07T14:12:29.614765+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/blog host=nameless-savannah-7872.herokuapp.com fwd="218.194.36.91" dyno= connect= service= status=503 bytes= 2013-06-07T14:12:37.461311+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=nameless-savannah-7872.herokuapp.com fwd="218.194.36.91" dyno= connect= service= status=503 bytes= 2013-06-07T14:12:37.994196+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=nameless-savannah-7872.herokuapp.com fwd="218.194.36.91" dyno= connect= service= status=503 bytes= 2013-06-07T14:14:48.197668+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/blog%EF%BC%8C%E4%B8%BB%E9%A1%B5%E6%98%AF%E9%BB%98%E8%AE%A4%E7%9A%84rails%E6%AC%A2%E8%BF%8E%E9%A1%B5%E9%9D%A2%EF%BC%8C%E6%88%91%E6%B2%A1%E6%9C%89%E5%8A%A8%E8%BF%87%E7%9A%84%E3%80%82%E8%BF%99%E5%88%B0%E5%BA%95%E6%98%AF%E5%93%AA%E7%9A%84%E9%97%AE%E9%A2%98%E5%91%A2 host=nameless-savannah-7872.herokuapp.com fwd="211.155.120.241" dyno= connect= service= status=503 bytes= 2013-06-07T14:14:51.690765+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=nameless-savannah-7872.herokuapp.com fwd="211.155.120.241" dyno= connect= service= status=503 bytes= 2013-06-07T14:14:52.088487+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=nameless-savannah-7872.herokuapp.com fwd="211.155.120.241" dyno= connect= service= status=503 bytes= 2013-06-07T14:16:59.043851+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/blog host=nameless-savannah-7872.herokuapp.com fwd="112.91.70.213" dyno= connect= service= status=503 bytes= 2013-06-07T14:16:59.851819+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=nameless-savannah-7872.herokuapp.com fwd="112.91.70.213" dyno= connect= service= status=503 bytes= 2013-06-07T14:17:01.069446+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=nameless-savannah-7872.herokuapp.com fwd="112.91.70.213" dyno= connect= service= status=503 bytes= 2013-06-07T14:17:02.285538+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=nameless-savannah-7872.herokuapp.com fwd="112.91.70.213" dyno= connect= service= status=503 bytes= 2013-06-07T14:17:02.993450+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=nameless-savannah-7872.herokuapp.com fwd="112.91.70.213" dyno= connect= service= status=503 bytes= 2013-06-07T14:20:44.920000+00:00 heroku[web.1]: State changed from crashed to starting 2013-06-07T14:20:47.473386+00:00 heroku[web.1]: Starting process with commandbundle exec rails server -p 13175 2013-06-07T14:20:57.147919+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 2013-06-07T14:20:57.148644+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 2013-06-07T14:21:00.780422+00:00 app[web.1]: => Booting WEBrick 2013-06-07T14:21:00.780422+00:00 app[web.1]: => Rails 3.2.12 application starting in production on http://0.0.0.0:13175 2013-06-07T14:21:00.780422+00:00 app[web.1]: => Call with -d to detach 2013-06-07T14:21:00.780422+00:00 app[web.1]: => Ctrl-C to shutdown server 2013-06-07T14:21:00.784736+00:00 app[web.1]: Exiting 2013-06-07T14:21:00.786789+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application/configuration.rb:115:indatabase_configuration' 2013-06-07T14:21:00.786789+00:00 app[web.1]: (erb):9:in rescue in <main>': Invalid DATABASE_URL (RuntimeError) 2013-06-07T14:21:00.786789+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:36:inexecute_hook' 2013-06-07T14:21:00.786996+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:42:in run_load_hooks' 2013-06-07T14:21:00.786996+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/base.rb:720:in' 2013-06-07T14:21:00.786996+00:00 app[web.1]: from /app/app/models/post.rb:1:in <top (required)>' 2013-06-07T14:21:00.786996+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:inrequire' 2013-06-07T14:21:00.786996+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in block in require' 2013-06-07T14:21:00.786996+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:inload_dependency' 2013-06-07T14:21:00.786996+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in require' 2013-06-07T14:21:00.786789+00:00 app[web.1]: from (erb):6:in' 2013-06-07T14:21:00.786789+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:36:in instance_eval' 2013-06-07T14:21:00.787154+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:230:inblock in constantize' 2013-06-07T14:21:00.786789+00:00 app[web.1]: from /usr/local/lib/ruby/1.9.1/erb.rb:753:in eval' 2013-06-07T14:21:00.786789+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/railtie.rb:78:inblock (2 levels) in class:Railtie' 2013-06-07T14:21:00.786789+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:42:in each' 2013-06-07T14:21:00.786996+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:359:inrequire_or_load' 2013-06-07T14:21:00.786789+00:00 app[web.1]: from /usr/local/lib/ruby/1.9.1/erb.rb:753:in result' 2013-06-07T14:21:00.787154+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:190:inconst_missing' 2013-06-07T14:21:00.786789+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:43:in block in run_load_hooks' 2013-06-07T14:21:00.786996+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:192:inblock in const_missing' 2013-06-07T14:21:00.786996+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:502:in load_missing_constant' 2013-06-07T14:21:00.787154+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:190:ineach' 2013-06-07T14:21:00.787154+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:260:in safe_constantize' 2013-06-07T14:21:00.787154+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/params_wrapper.rb:152:in_default_wrap_model' 2013-06-07T14:21:00.787154+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/params_wrapper.rb:133:in inherited' 2013-06-07T14:21:00.787579+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/abstract_controller/railties/routes_helpers.rb:7:inblock (2 levels) in with' 2013-06-07T14:21:00.787745+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:438:in block in eager_load!' 2013-06-07T14:21:00.788112+00:00 app[web.1]: from /app/config/environment.rb:5:in' 2013-06-07T14:21:00.788295+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:50:in tap' 2013-06-07T14:21:00.787745+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:436:ineach' 2013-06-07T14:21:00.787745+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in each' 2013-06-07T14:21:00.788112+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:ininitialize' 2013-06-07T14:21:00.787579+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/railties/paths.rb:7:in block (2 levels) in with' 2013-06-07T14:21:00.787579+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:225:inrequire_dependency' 2013-06-07T14:21:00.787154+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:229:in each' 2013-06-07T14:21:00.787579+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:inrequire' 2013-06-07T14:21:00.787154+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/params_wrapper.rb:169:in _set_wrapper_defaults' 2013-06-07T14:21:00.787579+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:inload_dependency' 2013-06-07T14:21:00.787579+00:00 app[web.1]: from /app/app/controllers/posts_controller.rb:1:in <top (required)>' 2013-06-07T14:21:00.787579+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:inblock in require' 2013-06-07T14:21:00.787745+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:436:in eager_load!' 2013-06-07T14:21:00.787154+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:229:inconstantize' 2013-06-07T14:21:00.787154+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/core_ext/string/inflections.rb:66:in safe_constantize' 2013-06-07T14:21:00.787579+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:inrequire' 2013-06-07T14:21:00.787745+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:55:in block in run_initializers' 2013-06-07T14:21:00.788112+00:00 app[web.1]: from /app/config.ru:3:inblock in ' 2013-06-07T14:21:00.787745+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:439:in block (2 levels) in eager_load!' 2013-06-07T14:21:00.788295+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:304:inwrapped_app' 2013-06-07T14:21:00.787745+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:438:in each' 2013-06-07T14:21:00.788112+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:ininstance_eval' 2013-06-07T14:21:00.788295+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in eval' 2013-06-07T14:21:00.788599+00:00 app[web.1]: from script/rails:6:inrequire' 2013-06-07T14:21:00.787745+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in run' 2013-06-07T14:21:00.788112+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:inmethod_missing' 2013-06-07T14:21:00.787579+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:359:in require_or_load' 2013-06-07T14:21:00.788112+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:inrun_initializers' 2013-06-07T14:21:00.788112+00:00 app[web.1]: from /app/config.ru:in <main>' 2013-06-07T14:21:00.787745+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:ininstance_exec' 2013-06-07T14:21:00.788112+00:00 app[web.1]: from /app/config.ru:3:in require' 2013-06-07T14:21:00.788295+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:50:in' 2013-06-07T14:21:00.788112+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:136:in initialize!' 2013-06-07T14:21:00.788112+00:00 app[web.1]: from /app/config.ru:innew' 2013-06-07T14:21:00.787579+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:313:in depend_on' 2013-06-07T14:21:00.787745+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application/finisher.rb:53:inblock in module:Finisher' 2013-06-07T14:21:00.788295+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:200:in app' 2013-06-07T14:21:00.788295+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/server.rb:70:instart' 2013-06-07T14:21:00.788295+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:55:in block in <top (required)>' 2013-06-07T14:21:00.788599+00:00 app[web.1]: from script/rails:6:in' 2013-06-07T14:21:00.788295+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in parse_file' 2013-06-07T14:21:00.788295+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/server.rb:46:inapp' 2013-06-07T14:21:00.788295+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:254:in `start' 2013-06-07T14:21:02.481410+00:00 heroku[web.1]: Process exited with status 1 2013-06-07T14:21:02.502216+00:00 heroku[web.1]: State changed from starting to crashed

@shangchen 在线吗?你没 at 我,刚看到,我还刷了几次,看没消息。。。

gemfile 里加 thin 了没? @shangchen

现在 heroku 的应用貌似要加这个 gem 才行。在线可以沟通下。。 别放弃,加油

#21 楼 @xazaj 没有加,我马上试一下

#21 楼 @xazaj 成功了,数据库也对了,非常感谢你啊!

成功就好,ruby 其实很多东西可玩,遇到问题别气馁,过了这一个个坎就看见阳光了,加油!!@shangchen

遇到和你相同的问题,不过解决办法不一样,附上我的解决方法:

  1. 先添加一个 postgresqladd-on,启动数据库服务 $ heroku addons:add heroku-postgresql:dev
  2. 然后在 config 中找到 HEROKU_POSTGRESQL 的 URL 参数 $ heroku config | grep HEROKU_POSTGRESQL 我的输出显示是: $ HEROKU_POSTGRESQL_NAVY_URL: postgres://root@root 则这个参数是 HEROKU_POSTGRESQL_NAVY_URL
  3. 把这个 URL 参数指向 DATABASE_URL, 注意命令里的参数哦!! $ heroku pg:promote HEROKU_POSTGRESQL_NAVY_URL
  4. 再运行heroku run rake db:migrate就可以了!
You need to Sign in before reply, if you don't have an account, please Sign up first.