Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise migration not working

I created a User model using Devise and whenever I use rake db:migrate I get the following issue:

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

undefined method `database_authenticatable' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x00000103fa1ff0>

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

I run the full trace with the --trace function but can't seem to figure out what the issue is. Here is the migration file:

class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
  t.database_authenticatable :null => false
  t.recoverable
  t.rememberable
  t.trackable
  t.confirmable

  # t.encryptable
  # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
  # t.token_authenticatable


  t.timestamps
 end

add_index :users, :email,                :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :confirmation_token,   :unique => true
# add_index :users, :unlock_token,         :unique => true
# add_index :users, :authentication_token, :unique => true
end

def self.down
  drop_table :users
  end
end
like image 552
tomciopp Avatar asked Jun 17 '11 22:06

tomciopp


1 Answers

Devise 2.0 eliminated helper functions for creating the database tables:

https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style

So what you need is:

create_table(TABLE_NAME) do |t|
  ## 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

  t.timestamps

end
like image 187
Amir Rubin Avatar answered Oct 01 '22 10:10

Amir Rubin