Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 添加token_authenticatable以使用迁移进行设计_Ruby On Rails_Database_Devise_Migration_Token - Fatal编程技术网

Ruby on rails 添加token_authenticatable以使用迁移进行设计

Ruby on rails 添加token_authenticatable以使用迁移进行设计,ruby-on-rails,database,devise,migration,token,Ruby On Rails,Database,Devise,Migration,Token,我已经使用Desive创建了一个用户模型,但是我现在想添加对token_Authenticatable的支持,所以我需要迁移这些添加。以下内容是否正确,以及token_authenticatable应该是什么类型 class AddAuthenticationTokenToUser < ActiveRecord::Migration def change add_column :users, :token_authenticatable add_index :us

我已经使用Desive创建了一个用户模型,但是我现在想添加对token_Authenticatable的支持,所以我需要迁移这些添加。以下内容是否正确,以及token_authenticatable应该是什么类型

class AddAuthenticationTokenToUser < ActiveRecord::Migration

  def change

    add_column :users, :token_authenticatable
    add_index  :users, :authentication_token, :unique => true

  end

end
class AddAuthenticationTokenToUsertrue
结束
结束
来自Github上的(第74行):

# t.string :authentication_token
如果要根据用户的令牌查找用户,那么添加索引是一个好主意


不要忘记将
设备:令牌\u authenticatable
添加到您的用户模型中。

设备2中已删除的迁移帮助程序的完整列表如下:

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

  ## Encryptable
  # t.string :password_salt

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

  ## Invitable
  # t.string :invitation_token

  t.timestamps
end

取自

,此模式样式在Desive 2.0中更改。列名应为
authentication\u token
rails g migration addauthenticationtokentokentoken\u authenticable:string:uniq
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

  ## Encryptable
  # t.string :password_salt

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

  ## Invitable
  # t.string :invitation_token

  t.timestamps
end