0

我正在使用paranoidgem 来将记录标记为已删除,而无需实际删除它们。要将记录标记为已删除,它使用附加列deleted_at

我有一个迁移,它将这样的列添加到所有 activerecord 子类中:

class AddDeletedAtToModels < ActiveRecord::Migration


def up
  Dir[Rails.root.join('app/models/**.rb')].each{ |f| require f }
  ActiveRecord::Base.subclasses.each do |klass|
    add_column klass.table_name.to_sym, :deleted_at, :datetime rescue Rails.logger.error("Can't add column to #{klass}")
  end
end

def down
  Dir[Rails.root.join('app/models/**.rb')].each{ |f| require f }
  ActiveRecord::Base.subclasses.each do |klass|
    remove_column klass.table_name.to_sym, :deleted_at
  end
end

结尾

但是该迁移失败并出现错误:

rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR:  current transaction is aborted, commands ignored until end of transaction block:           
      SELECT attr.attname
      FROM pg_attribute attr
      INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1]
      WHERE cons.contype = 'p'
        AND cons.conrelid = '"schema_migrations"'::regclass

我对 postgresql 不是很熟悉,所以问题是这种错误是什么意思,我做错了什么。这对 MySQL 工作得很好,但对 PostgreSQL 却不行。

4

0 回答 0