Devise migration on existing model

后端 未结 4 1292
北海茫月
北海茫月 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:02

    Instead of changing the create_table to change_table, you can just add the following line just before create_table:

    rename_table :users, :old_users_authlogic
    

    Then, right after the create_table:

    say_with_time 'Migrating users from Authlogic to Devise...' do
      execute "INSERT INTO users (id, email, ...) SELECT id, email FROM old_users_authlogic"
    end
    

    If you are using indexes with referential integrity, don't forget to update them to the new table, as the rename_table will make them point to old_users_authlogic.

提交回复
热议问题