Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Deleted User

Deploying to Heroku error

Hello I am running into some errors when trying to deploy my application to Heroku.


change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

PG::Error: ERROR: relation "users" does not exist

: ALTER TABLE "users" ADD COLUMN "first_name" character varying(255)

The repository for my project is here - https://github.com/tomheather/treebook and the Heroku url is here - http://fathomless-woodland-9405.herokuapp.com/

It seems I have successfully deployed the application onto the web however as you will see only the first page is accessible, and i fear something may have gone wrong within my code.

Here is the error message I get after running: heroku rake db:migrate

C:\Sites\treebook>heroku run rake db:migrate Running rake db:migrate attached to terminal... up, run.9889 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 i n your Gemfile, or fold them in to your app as lib/myplugin/* and config/initial izers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonr ails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from <top (requir ed)> at /app/Rakefile:7) 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 i n your Gemfile, or fold them in to your app as lib/myplugin/* and config/initial izers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonr ails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from <top (requir ed)> at /app/Rakefile:7) Migrating to CreateStatuses (20121212232335) == CreateStatuses: migrating ================================================= -- create_table(:statuses) NOTICE: CREATE TABLE will create implicit sequence "statuses_id_seq" for serial column "statuses.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "statuses_pkey" f or table "statuses" -> 0.0205s == CreateStatuses: migrated (0.0206s) ========================================

Migrating to AddDeviseToUsers (20121231172750) == AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

PG::Error: ERROR: relation "users" does not exist : ALTER TABLE "users" ADD COLUMN "first_name" character varying(255) /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/postgresql_adapter.rb:640:in async_exec' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/postgresql_adapter.rb:640:inblock in execute' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract_adapter.rb:280:in block in log' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/notifi cations/instrumenter.rb:20:ininstrument' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract_adapter.rb:275:in log' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/postgresql_adapter.rb:639:inexecute' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/postgresql_adapter.rb:989:in add_column' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/schema_definitions.rb:479:inblock in string' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/schema_definitions.rb:468:in each' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/schema_definitions.rb:468:instring' /app/db/migrate/20121231172750_add_devise_to_users.rb:4:in block in up' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/schema_statements.rb:243:inchange_table' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:450:in block in method_missing' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:424:inblock in say_with_time' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:424:in say_with_time' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:444:inmethod_missing' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:334:in method_missing' /app/db/migrate/20121231172750_add_devise_to_users.rb:3:inup' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:358:in up' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:396:inblock (2 levels) in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:396:in block in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/connection_pool.rb:118:inwith_connection' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:377:in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:512:inmigrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:704:in block (2 levels) in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:759:incall' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:759:in block in ddl_transaction' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/database_statements.rb:190:intransaction' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transact ions.rb:208:in transaction' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:759:inddl_transaction' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:703:in block in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:684:ineach' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:684:in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:554:inup' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:535:in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/railties /databases.rake:153:inblock (2 levels) in <top (required)>' Tasks: TOP => db:migrate (See full trace by running task with --trace)

12 Answers

What does your db/schema.rb look like?

Deleted User

https://github.com/tomheather/treebook/blob/master/db/schema.rb

encoding: UTF-8

ActiveRecord::Schema.define(:version => 20121231220507) do

create_table "statuses", :force => true do |t| t.text "content" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.integer "user_id" end

add_index "statuses", ["user_id"], :name => "index_statuses_on_user_id"

create_table "users", :force => true do |t| t.string "email", :default => "", :null => false t.string "encrypted_password", :default => "", :null => false t.string "first_name" t.string "last_name" t.string "profile_name" t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", :default => 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end

add_index "users", ["email"], :name => "index_users_on_email", :unique => true add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true

end

Are you using SQLite locally?

Deleted User

yes I think so - https://github.com/tomheather/treebook/blob/master/Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.1'

Bundle edge Rails instead:

gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'devise' gem 'simple_form'

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

group :production do gem 'pg' end

I've seen a lot of times where migrations work in either SQLite or postgres, but don't work for both.

If you don't care about the data try:

heroku pg:reset
heroku run rake db:migrate
heroku restart
Deleted User

Which database should i provide? sorry I am new to this

C:\Sites\treebook>heroku pg:reset ! Usage: heroku pg:reset DATABASE ! Must specify DATABASE to reset.

Run heroku config to see your ENV vars, then try:

heroku pg:reset DATABASE_URL
Deleted User

Tried that - reset the databases successfully -

C:\Sites\treebook>heroku pg:reset fathomless-woodland-9405

Resetting HEROKU_POSTGRESQL_VIOLET_URL (DATABASE_URL)... done

But when I run heroku run rake db:migrate i still get this error:
any ideas anyone? thanks for your help so far.

Migrating to AddDeviseToUsers (20121231172750) == AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

PG::Error: ERROR: relation "users" does not exist : ALTER TABLE "users" ADD COLUMN "first_name" character varying(255) /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/postgresql_adapter.rb:640:in async_exec' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/postgresql_adapter.rb:640:inblock in execute' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract_adapter.rb:280:in block in log' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/notifi cations/instrumenter.rb:20:ininstrument' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract_adapter.rb:275:in log' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/postgresql_adapter.rb:639:inexecute' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/postgresql_adapter.rb:989:in add_column' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/schema_definitions.rb:479:inblock in string' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/schema_definitions.rb:468:in each' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/schema_definitions.rb:468:instring' /app/db/migrate/20121231172750_add_devise_to_users.rb:4:in block in up' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/schema_statements.rb:243:inchange_table' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:450:in block in method_missing' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:424:inblock in say_with_time' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:424:in say_with_time' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:444:inmethod_missing' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:334:in method_missing' /app/db/migrate/20121231172750_add_devise_to_users.rb:3:inup' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:358:in up' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:396:inblock (2 levels) in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:396:in block in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/connection_pool.rb:118:inwith_connection' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:377:in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:512:inmigrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:704:in block (2 levels) in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:759:incall' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:759:in block in ddl_transaction' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connecti on_adapters/abstract/database_statements.rb:190:intransaction' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transact ions.rb:208:in transaction' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:759:inddl_transaction' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:703:in block in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:684:ineach' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:684:in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:554:inup' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migratio n.rb:535:in migrate' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/railties /databases.rake:153:inblock (2 levels) in <top (required)>' Tasks: TOP => db:migrate

It looks like you're running a migration to change the users table BEFORE it exists. Your migrations all should be prepended with a timestamp.

Example:
db/migrate/20121031233110_create_users.rb

For some reason AddDeviseToUsers has a earlier timestamp than your actual CreateUsers migration. Try renaming the files so you're creating users BEFORE your run AddDeviseToUsers.

Deleted User

ok thanks that makes some sense i have re-named it to 20129999999999_add_devise_to_users.rb so presumably it will run later than everything else and still i am getting errors, i do not have a create_users.rb in my db folder for this treehouse treebook will this matter?

Be careful about the new timestamp. I would change the timestamp to just after your latest migration. That way new migrations' timestamps are AFTER it.