添加token_authenticatable以设计迁移

Und*_*ion 13 database migration ruby-on-rails token devise

我已经使用设计创建了一个用户模型,但我现在想添加对token_authenticable的支持,所以我需要迁移这些添加.以下是否正确,token_authenticatable应该是什么类型?

class AddAuthenticationTokenToUser < ActiveRecord::Migration

  def change

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

  end

end
Run Code Online (Sandbox Code Playgroud)

Gaz*_*ler 17

从Github上的devise 2.0生成器(第74行):

# t.string :authentication_token
Run Code Online (Sandbox Code Playgroud)

如果您要根据其令牌查找用户,则添加索引是个好主意.

这是设计1.5文件


Nic*_*gan 13

add_column :users, :token_authenticatable, :string
Run Code Online (Sandbox Code Playgroud)

不要忘记添加devise :token_authenticatable到您的用户模型.

  • 在架构2.0中更改了此架构样式.列名应为`authentication_token`.https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style (2认同)