Devise migration on existing model

后端 未结 4 1283
北海茫月
北海茫月 2020-12-08 17:47

I\'m migrating from Authlogic to Devise.

UPDATED:

The migration of devise tries to re-create the table users, so i changed as you can see below the create_

4条回答
  •  眼角桃花
    2020-12-08 18:22

    The error that you're getting is because you are trying to recreate the email field which you already have. The email field is created in the devise helper t.database_authenticatable. You can use your old user table with the new system, but you don't need to include t.database_authenticatable, you just need to rename your old field names. Looking in the Documentation for Devise, you can see that database_authenticatable just creates three fields: email, encrypted_password and password_salt. They are the same as the email, crypted_password, and password_salt that you already have in your authlogic user table, so you can use change_table like so:

    def self.up
      change_table(:users) do |t|
        t.recoverable
        t.trackable
        # rememberable uses remember_token, but this field is different
        t.rename :remember_token_expires_at, :remember_created_at
        # these fields are named differently in devise
        t.rename :crypted_password, :encrypted_password
      end
    end
    

提交回复
热议问题