2011-12-28 33 views
7

EDIT: Lời khuyên chung là sử dụng CEDAR ngăn xếp.Heroku on Rails - Không hợp lệ DATABASE_URL

Khá mới đối với RoR, Gems, Heroku và Git. Làm theo hướng dẫn: http://ruby.railstutorial.org/book/ruby-on-rails-tutorial

trình trơn tru trên localhost, khi triển khai tới Heroku có ConnectionNotEstablished lỗi, mà đã được giải quyết ở đây: https://stackoverflow.com/questions/7542745/heroku-error-activerecordconnectionnotestablished(BTW: sau cùng hướng dẫn) Sau khi thay đổi cơ sở dữ liệu sản xuất để PostgreSQL (đá quý 'pg ') nó tạo ra một lỗi:

cách truy cập vào trang web hoạt động

An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

Cố gắng này - Heroku app crashed, receiving "Invalid DATABASE URL" when attempting heroku rake db:migrate - Heroku rake db: di chuyển

rake aborted! 
Invalid DATABASE_URL 

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

Heroku console

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 

bản ghi Heroku

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] 
3:09+00:00 heroku[api]: Release v7 created by [email protected] 
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= 

Loại gặp khó khăn, xin vui lòng giúp đỡ (điểm theo hướng bên phải)

Tất nhiên

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

Trả lời

2

Điều đầu tiên tôi muốn bắt đầu với là di chuyển của bạn ứng dụng với Stack Cedar - nó hỗ trợ Rails 3.1 ra khỏi hộp mà không cần phải làm bất cứ điều gì xung quanh.

Khi bạn tạo ứng dụng của bạn qua heroku create làm điều đó như

heroku create --stack cedar 

và sau đó repush để ngăn xếp này - bạn có thể thấy vấn đề của mình tất cả sẽ biến mất. Điều cần nhớ là thêm 'chạy' vào các lệnh của bạn, bảng điều khiển chạy heroku, heroku chạy rake db: di chuyển, v.v.

0

Bạn có thể vui lòng nhập cấu hình heroku --long - (tên ứng dụng). Vui lòng đăng kết quả, đặc biệt là DATABASE_URL.

Cần thêm thông tin. Ngoài ra, chắc chắn đảm bảo bạn đang ở trên ngăn xếp tuyết tùng như đã đề cập ở trên.

+0

BUNDLE_WITHOUT => phát triển: test LANG => en_US.UTF-8 RACK_ENV => sản xuất Di chuyển sang tuyết tùng, như đề xuất trong câu trả lời khác nữa. –

+0

Di chuyển đến tuyết tùng không phải là tầm thường, một số vấn đề với postgre/sqlite Thời gian tới sẽ sử dụng ** - database = postgresql ** ngay từ đầu. Dù sao nhờ giúp đỡ, bây giờ tôi sẽ hoàn thành hướng dẫn mà không cần triển khai ... –

+0

Đó là thiếu URL cơ sở dữ liệu .... bạn có cơ sở dữ liệu được chia sẻ thêm vào cài đặt không? Nó sẽ nhổ ra URL cơ sở dữ liệu và bên dưới URL cơ sở dữ liệu được chia sẻ. Nếu có vấn đề, có vẻ như nó ở đó. Nên có ít nhất một giá trị mặc định. –

3

Tôi đã gặp sự cố tương tự. Hóa ra tôi không có một cơ sở dữ liệu liên kết với ứng dụng. Bạn sẽ thấy điều này với lệnh heroku config đơn giản-- bạn sẽ thấy một số URL cơ sở dữ liệu trỏ đến Amazon.ví dụ:

$ h config 
DATABASE_URL  => postgres://fakedexgwa:[email protected]1.amazonaws.com/fakedexgwa 

Dù sao, tôi cố định này bằng cách tạo ra một thương hiệu ứng dụng mới và triển khai nó. Tôi đã thử không quan tâm xung quanh trong màn hình cấu hình, nhưng không thể khắc phục được sự cố.

Tôi không chắc đây có phải là nguyên nhân tương tự như của bạn hay không: Tôi đã tạo một ứng dụng Ruby đơn giản, triển khai và sau đó tạo ứng dụng Rails. Tôi đã không nhận được bất kỳ cơ sở dữ liệu nào được nêu ra, và tôi tự hỏi nếu Heroku bằng cách nào đó quyết định về việc triển khai đầu tiên mà tôi không cần một cơ sở dữ liệu.

+0

Hey gọi tôi là điên, nhưng bạn có thể muốn thay đổi mật khẩu db thực tế của bạn hoặc chỉnh sửa bài đăng này, vì vậy thông tin đăng nhập cơ sở dữ liệu của bạn không được phát sóng cho mọi người? – culix

+0

Xin chào! Tôi đã thay đổi bài đăng để nó rõ ràng là dữ liệu giả mạo ... fyi Tôi đã không đăng thông tin thực sự của tôi ban đầu. – ndp

+0

OK, phew! Rất vui được nghe! Chỉ cần cố gắng giúp đỡ. – culix

17

Bạn cần đặt biến môi trường DATABASE_URL với đường dẫn đến db đăng bài trực tuyến của bạn.

Thử chạy heroku pg. Nếu đầu ra là "myapp không có cơ sở dữ liệu heroku-postgresql." thì trước tiên bạn cần thêm tiện ích bổ sung PostgreSQL. Nó sẽ tạo ra một db postgres cho bạn trên Amazon AWS.

heroku addons:add heroku-postgresql:hobby-basic 

(sở thích cơ bản là kế hoạch miễn phí)

Để tìm URL cho cơ sở dữ liệu mới của bạn, hãy chạy

heroku config 

Bạn sẽ thấy một biến mà bắt đầu với HEROKU_POSTGRESQL. Sao chép giá trị của nó (nó nên bắt đầu với postgres:// và sử dụng nó để thiết lập DATABASE_URL

heroku config:set DATABASE_URL=postgres://your-db-url 
1

Vui lòng đọc bài viết này:

ClearDB MySQL Database

Commands:

heroku config

hoặc nếu bạn sử dụng cho một đường ray dự án nhiều dự án Heroku

heroku config --app your_app_name

Thêm URL Cơ sở dữ liệu:

heroku config:set DATABASE_URL='mysql://adffdadf2341:[email protected]/heroku_db?reconnect=true'

.210

Nếu bạn sử dụng đá quý mysql2 phải để thay thế mysql với mysql2

heroku config:set DATABASE_URL='mysql2://adffdadf2341:[email protected]/heroku_db?reconnect=true'

Tôi hy vọng những cấu hình có thể được sử dụng cho các cơ sở dữ liệu PostgreSQL, NoSQL hoặc cơ sở dữ liệu khác.

Các vấn đề liên quan