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

Tyler Leskanic
Tyler Leskanic
1,857 Points

Rake aborted! db:migrate

So when setting up Devise on the treebook project after generating the add user table I get a error when trying to migrate:

\treebook> rake db:migrate
rake aborted!
cannot load such file -- 1.9/bcrypt_ext
/treebook/app/models/user.rb:5:in `<class:User>'
/treebook/app/models/user.rb:1:in `<top (required)>'
/treebook/config/routes.rb:5:in `block in <top (required)>'
/treebook/config/routes.rb:1:in `<top (required)>'
C:in `execute_if_updated'
/treebook/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

Any help in the right direction would be appreciated as I am new to rails.

8 Answers

Tyler Leskanic
Tyler Leskanic
1,857 Points

Yes and I just did it again for good measure and I still get rake aborted.

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

Do you have all the right gems in your Gemfile? I'll also ping Jason Seifer as he may be able to spot the issue.

Tyler Leskanic
Tyler Leskanic
1,857 Points

Gemfile pasted below:

source 'http://rubygems.org'

gem 'rails', '3.2.13'

Bundle edge Rails instead:

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

gem 'sqlite3' gem 'devise'

Gems used only for assets and not required

in production environments by default.

group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', :platforms => :ruby

gem 'uglifier', '>= 1.0.3' end

gem 'jquery-rails'

To use ActiveModel has_secure_password

gem 'bcrypt-ruby', '~> 3.0.0'

To use Jbuilder templates for JSON

gem 'jbuilder'

Use unicorn as the app server

gem 'unicorn'

Deploy with Capistrano

gem 'capistrano'

To use debugger

gem 'debugger'

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

try

gem 'bcrypt-ruby', '~> 3.0.0', :require => "bcrypt"
Tyler Leskanic
Tyler Leskanic
1,857 Points

That did fix the the first issue. Now it's complaining about a duplicate column name. I opened the db file and I see no duplicates anywhere.

PS \treebook> rake db:migrate == AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: first_name: ALTER TABLE "users" ADD "first_name" varchar(255)/treebook/db/migrate/20130709160347_add_devise_to_users.rb:4:in block in up' /treebook/db/migrate/20130709160347_add_devise_to_users.rb:3:inup' C:in `migrate' Tasks: TOP => db:migrate (See full trace by running task with --trace) PS \treebook>

Tyler Leskanic
Tyler Leskanic
1,857 Points

The issue was. The file generated by devise had change_table(:users) at top. I changed it to create_table :users and can now migrate just fine.

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

What's the contents of the 20130709160347_add_devise_to_users.rb file?

Tyler Leskanic
Tyler Leskanic
1,857 Points

class AddDeviseToUsers < ActiveRecord::Migration def self.up change_table(:users) do |t| t.string :first_name t.string :last_name t.string :profile_name ## Database authenticatable t.string :email, :null => false, :default => "" t.string :encrypted_password, :null => false, :default => ""

         ## Recoverable
         t.string   :reset_password_token
         t.datetime :reset_password_sent_at

         ## Rememberable
         t.datetime :remember_created_at

          ## Trackable
          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

          ## Confirmable
          # t.string   :confirmation_token
          # t.datetime :confirmed_at
          # t.datetime :confirmation_sent_at
          # t.string   :unconfirmed_email # Only if using reconfirmable

          ## Lockable
          # t.integer  :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
         # t.string   :unlock_token # Only if unlock strategy is :email or :both
        # t.datetime :locked_at

        ## Token authenticatable
        # t.string :authentication_token


        # Uncomment below if timestamps were not included in your original model.
       # t.timestamps
    end

    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
  end

  def self.down
    # By default, we don't want to make any assumption about how to roll back a migration when your
    # model already existed. Please edit below which fields you would like to remove in this migration.
    raise ActiveRecord::IrreversibleMigration
  end
end
Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

Also do a rails console and type User and hit enter and what does that return?

Tyler Leskanic
Tyler Leskanic
1,857 Points

=> User(id: integer, first_name: string, last_name: string, profile_name: string, email: string, encrypted_password: str ing, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integ er, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: string, last_sign_in_ip: string, create d_at: datetime, updated_at: datetime)

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

So it looks like you've already got the fields like first_name, last_name etc. You could try and rollback or if there's no data yet drop the database.

If you run rake -T and it'll list the database tasks. I suspect when there was an issue with the gem requirements that it got part way through the migration.

Tyler Leskanic
Tyler Leskanic
1,857 Points

I've tried rolling back. I've also tried db:drop, db:create and db:migrate again to start from scratch and still get the same error.

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

How many migration files do you have? Is there another users table migration?

Tyler Leskanic
Tyler Leskanic
1,857 Points

Under migration, I have two files.

Tyler Leskanic
Tyler Leskanic
1,857 Points

20130708155250_create_statuses 20130709174157_add_devise_to_users

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

Look in both files and see if there's any code duplicate with regard to the users table. If not it looks like the database isn't being dropped.

Try deleting the sqlite database in your db folder and try again.

unknown68a86d404924:treebook dennishegstad$ rake -t ** Invoke default (first_time) ** Invoke test (first_time) ** Execute test ** Invoke test:run (first_time) ** Execute test:run ** Invoke test:units (first_time) ** Invoke test:prepare (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:load_config (first_time) ** Execute db:load_config ** Execute db:abort_if_pending_migrations You have 1 pending migrations: 20130826192456 AddDeviseToUsers Run rake db:migrate to update your database then try again. unknown68a86d404924:treebook dennishegstad$ rake db:migrate == AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in initialize' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:innew' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in prepare' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:134:inexecute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in block in execute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in instrument' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in execute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_statements.rb:264:inadd_column' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:400:in add_column' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:479:inblock in string' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468:in each' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468:instring' /Users/dennishegstad/treebook/db/migrate/20130826192456_add_devise_to_users.rb:5:in block in up' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_statements.rb:243:inchange_table' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:466:in block in method_missing' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:inblock in say_with_time' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in say_with_time' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:458:inmethod_missing' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:334:in method_missing' /Users/dennishegstad/treebook/db/migrate/20130826192456_add_devise_to_users.rb:3:inup' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:370:in up' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:inblock (2 levels) in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in block in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:inwith_connection' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:389:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:528:inmigrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:720:in block (2 levels) in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:incall' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in block in ddl_transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:inddl_transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:719:in block in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:ineach' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:570:inup' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:551:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:193:inblock (2 levels) in <top (required)>' Tasks: TOP => db:migrate (See full trace by running task with --trace) unknown68a86d404924:treebook dennishegstad$

I'm having the same issue and unable to perform db:migrate on this step with adding devise to users. Been trying to fix for a few hours.

Yes, neither of those worked. If they had worked I wouldn't have commented in addition to what he tried :-)

unknown68a86d404924:treebook dennishegstad$ rake db:migrate == DeviseCreateUsers: migrating ============================================== -- create_table(:users) -> 0.0916s -- add_index(:users, :email, {:unique=>true}) -> 0.0012s -- add_index(:users, :reset_password_token, {:unique=>true}) -> 0.0007s == DeviseCreateUsers: migrated (0.0939s) =====================================

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

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in initialize' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:innew' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in prepare' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:134:inexecute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in block in execute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in instrument' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in execute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_statements.rb:264:inadd_column' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:400:in add_column' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:479:inblock in string' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468:in each' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468:instring' /Users/dennishegstad/treebook/db/migrate/20130826192456_add_devise_to_users.rb:5:in block in up' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_statements.rb:243:inchange_table' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:466:in block in method_missing' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:inblock in say_with_time' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in say_with_time' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:458:inmethod_missing' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:334:in method_missing' /Users/dennishegstad/treebook/db/migrate/20130826192456_add_devise_to_users.rb:3:inup' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:370:in up' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:inblock (2 levels) in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in block in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:inwith_connection' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:389:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:528:inmigrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:720:in block (2 levels) in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:incall' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in block in ddl_transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:inddl_transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:719:in block in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:ineach' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:570:inup' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/migration.rb:551:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:193:inblock (2 levels) in <top (required)>' Tasks: TOP => db:migrate (See full trace by running task with --trace)

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

Can you open up the migration and remove the email line? That seems to be the issue with this particular migration.

Im having the same issue.

I had two devise files: 'add devise to user.rb' and 'devise create users.rb' I just deleted the 'add devise to users.rb' in the db migrate folder and it worked for me.