3

undefined method database_authenticatable' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition:0xd715388>

The migration is:

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable
      t.timestamps
    end
    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
  end
  def self.down
    drop_table :users
  end
end
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497

2 Answers2

9

If I'm not mistaken, devise changed it's generated migration style from

create_table(:user) do |t|
  t.database_authenticatable
end

to

create_table(:user) do |t|
  ## Database authenticatable
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""
end

after version 2.0.

UPDATE: See this wiki.

cdesrosiers
  • 8,862
  • 2
  • 28
  • 33
  • +1 Useful. But what if this is an existing rails application and the user migration is one of the early ones, what is the correct approach? Should I edit that? Delete it and redo a brand new one? Do a migration to drop the old, add the new? The correct answer to these questions will help guide me to a good solution – Michael Durrant Feb 06 '13 at 17:25
  • I check the above wiki reference - https://github.com/plataformatec/devise/wiki/How-To%3a-Upgrade-to-Devise-2.0-migration-schema-style - and it is helpful, e.g. "You will need to change your original Devise migration(s) to not use the Before helpers, but instead use the fields listed..." – Michael Durrant Feb 06 '13 at 17:27
  • maybe put the update link to wiki at the top of this post instead of the bottom? – handler Dec 13 '14 at 19:11
0

This works for me:

create_table(:users) do |t|
  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.encryptable
  # t.confirmable
  # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
  # t.token_authenticatable


  t.timestamps
end