简体   繁体   中英

Tried deploying on Heroku, didn't work and now local server not working

UPDATE - SOLVED: Both my local server and heroku wouldn't work. Two main components fixed this problem.

Thank you everyone for your help and support! Knowing that there are people out there willing to help is invaluable in this learning process; hence, my effort to document this error/solution for future coders to bang their heads a little less.

:( My app was working locally and then I followed the directions to push onto Heroku.

I got Heroku's super descriptive and comforting error message: "We're sorry, but something went wrong."

In other words, now my app doesn't work locally or on heroku... would love to solve this with your help. Thank you.

So I tried some things (in this order):

  • I took out gem 'sqlite3' and replaced it with gem 'pg'
  • In my gemfile, included ruby '2.0.0'
  • heroku rake db:migrate

I tried solving the local problem first.

When I tried rails server (to test locally), I got the following error:

Somehow when deploying to Heroku, there was inconsistency with my Ruby version, using 2.0.0 and gemfile was expected 1.8.

   ms.rb:777:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:211:in `activate'
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:1056:in `gem'
        from /usr/bin/rails:18
    Davids-MacBook-Air-6:portfolio davidngo$ rails server
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:777:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:211:in `activate'
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:1056:in `gem'
        from /usr/bin/rails:18

What solved it for me:

  • reinstalled my ruby 2.0.0 by running rvm reinstall ruby 2.0.0
  • run bundle install #=> when I saw "Your Ruby version is 2.0.0, but your Gemfile specified 1.8" I knew that I was in the right direction because this error is super common/all over StackOverFlow

The Main Heroku Problem:

State changed from starting to complete
2013-08-20T03:29:43.118968+00:00 heroku[run.2135]: Error R99 (Platform error) -> Failed to launch the dyno within 10 seconds
2013-08-20T03:29:43.119187+00:00 heroku[run.2135]: Stopping process with SIGKILL
2013-08-20T03:31:00.784270+00:00 heroku[router]: at=info method=GET path=/ host=shrouded-citadel-6554.herokuapp.com fwd="107.193.213.240" dyno=web.1 connect=2ms service=24ms status=500 bytes=643
2013-08-20T03:31:00.800238+00:00 app[web.1]: 
2013-08-20T03:31:00.800238+00:00 app[web.1]: Started GET "/" for 107.193.213.240 at 2013-08-20 03:31:00 +0000
2013-08-20T03:31:00.800238+00:00 app[web.1]: 
2013-08-20T03:31:00.802209+00:00 app[web.1]: Processing by CollectionsController#index as HTML
2013-08-20T03:31:00.808688+00:00 app[web.1]: Completed 500 Internal Server Error in 6ms
2013-08-20T03:31:00.810234+00:00 app[web.1]: 
2013-08-20T03:31:00.810234+00:00 app[web.1]:              WHERE a.attrelid = '"collections"'::regclass
2013-08-20T03:31:00.810234+00:00 app[web.1]:                                         ^
2013-08-20T03:31:00.810234+00:00 app[web.1]: LINE 4:              WHERE a.attrelid = '"collections"'::regclass
2013-08-20T03:31:00.810234+00:00 app[web.1]: :             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
2013-08-20T03:31:00.810234+00:00 app[web.1]:               FROM pg_attribute a LEFT JOIN pg_attrdef d
2013-08-20T03:31:00.810234+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::Error: ERROR:  relation "collections" does not exist
2013-08-20T03:31:00.810234+00:00 app[web.1]:              ORDER BY a.attnum
2013-08-20T03:31:00.810234+00:00 app[web.1]:                 ON a.attrelid = d.adrelid AND a.attnum = d.adnum
2013-08-20T03:31:00.810234+00:00 app[web.1]:                AND a.attnum > 0 AND NOT a.attisdropped
2013-08-20T03:31:00.810392+00:00 app[web.1]: ):
2013-08-20T03:31:00.810392+00:00 app[web.1]:   app/controllers/collections_controller.rb:4:in `index'
2013-08-20T03:31:00.810392+00:00 app[web.1]: 
2013-08-20T03:31:00.810392+00:00 app[web.1]: 
2013-08-20T03:31:01.224316+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=shrouded-citadel-6554.herokuapp.com fwd="107.193.213.240" dyno=web.1 connect=3ms service=8ms status=200 bytes=0

What solved it for me:

heroku pg:reset DATABASE --confirm YOUR_APP_NAME
heroku run rake db:setup
heroku restart
heroku open

Related & Important Files:

In database.yml: development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000

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

production:
  adapter: postgresql
  encoding: utf8
  database: portfolio_production
  pool: 5
  username:
  password:

In Gemfile:

source 'https://rubygems.org'

ruby '2.0.0'

gem 'rails', '3.2.3'

group :development, :test do
    gem 'sqlite3'
end

group :production do
    gem 'pg'
end

It looks like as Heroku did'nt run db:migrate on deployment.

Try to run

 #heroku run rake db:migrate

on console after deploying it again.

After running a migration you'll want to restart your app with

#heroku restart 

to reload the schema and pickup any schema changes.

You still can use sqlite for development your Gemfile should look like this:

group :development, :test do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end

This will let you to use postgresql on Heroku(production mode) and sqlite locally. Don't forget to run your database migration as soon as you will deploy on heroku. You can run migrations with heroku run rake db:migrate command.

You will need to change your database.yml file to reflect new adapter . Also you should have postgres setup locally.

New database.yml file should look like -

development:
  adapter: postgresql
  encoding: utf8
  database: app_name_development
  pool: 5
  username:
  password:

test:
  adapter: postgresql
  encoding: utf8
  database: app_name_test
  pool: 5
  username:
  password:

production:
  adapter: postgresql
  encoding: utf8
  database: app_name_production
  pool: 5
  username:
  password:

After you have modified the database.yml run

rake db:drop db:create db:migrate

To create fresh database in Postgres.

You can have a different adapter locally than in production, that is no problem. When deploying to Heroku, you need to run your migrations by hand, it's not part of the deploy process.

So, you first deploy it regularly and then you run heroku run rake --trace db:migrate . The error that you are seeing tells you that the table for Collection model doest not exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM