Rails acts_as_paranoid migration在确认设计时给出错误

时间:2015-11-05 06:38:56

标签: ruby-on-rails devise acts-as-paranoid ruby-paranoia

class Advertiser < ActiveRecord::Base
devise :database_authenticatable, :registerable,:recoverable, :rememberable, :trackable, :validatable,:confirmable

acts_as_paranoid    
end

我首先添加了Devise gem而没有确认选项。然后我在此迁移中添加了确认选项:

class AddConfirmableToDevise < ActiveRecord::Migration
def up
add_column :advertisers, :confirmation_token, :string
add_column :advertisers, :confirmed_at, :datetime
add_column :advertisers, :confirmation_sent_at, :datetime

add_index :advertisers, :confirmation_token, :unique => true

Advertiser.update_all(:confirmed_at => Time.now)

end
end

当我运行迁移时,它会出错

PG::UndefinedColumn: ERROR:  column advertisers.deleted_at does not exist
LINE 1: ...onfirmed_at" = '2015-11-05 06:24:26.513079' WHERE "advertise...

1 个答案:

答案 0 :(得分:0)

更改迁移文件,如下所示:

class AddConfirmableToDevise < ActiveRecord::Migration
  def up
    add_column :advertisers, :confirmation_token, :string
    add_column :advertisers, :confirmed_at, :datetime
    add_column :advertisers, :confirmation_sent_at, :datetime
    add_index :advertisers, :confirmation_token, unique: true
    add_column :advertisers, :deleted_at, :time
    execute("UPDATE advertisers SET confirmed_at = NOW()")
  end

  def down
    remove_columns :advertisers, :confirmation_token, :confirmed_at, :confirmation_sent_at
  end 
end

有关详细信息,请参阅devise