1

我想部署一个登台服务器,我使用 mina 进行部署。

我愿意mina staging deploy(在迁移之前工作良好)

== 20161117192144 CreateHealthCenter: migrating ===============================
   -- add_column(:places, :health_center, :boolean, {:default=>false})
      -> 0.0152s
   rake aborted!
   StandardError: An error has occurred, this and all later migrations canceled:

   PG::UndefinedTable: ERROR:  relation "versions" does not exist
   LINE 5:                WHERE a.attrelid = '"versions"'::regclass
                                             ^
   :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                        pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                   FROM pg_attribute a LEFT JOIN pg_attrdef d
                     ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                  WHERE a.attrelid = '"versions"'::regclass
                    AND a.attnum > 0 AND NOT a.attisdropped
                  ORDER BY a.attnum

Place模型具有 has_paper_trail(在 app/models/place.rb 中)

paper_trail 的迁移是 2017 年的迁移

我有 4 个创建实例,例如:

Place.create( name: "CESFAM" , address: "Av R 740" , health_center: true )

我认为这是问题所在(现在我知道我不必在迁移中执行 data_migration),但我想知道替代解决方案

我认为这个解决方案

  1. 向 paper_trail 添加一些配置
  2. 编辑迁移删除数据迁移
  3. 其他

(对不起我糟糕的英语)

编辑: - Rails 4 - 纸迹 8.1.2

编辑2:

迁移 20161117192144

class CreateHealthCenter < ActiveRecord::Migration
    def up
        add_column :places, :health_center , :boolean , default: false

        Place.create( name: "CESFAM" , address: "R 740" , health_center: true )
        Place.create( name: "CECOF" , address: "S 185" , health_center: true )
        Place.create( name: "COSAM" , address: "C 1892" , health_center: true )
    end

    def down
        remove_column :places, :health_center
        Place.where("name = 'CESFAM'").delete_all
        Place.where("name = 'CECOF'").delete_all
        Place.where("name = 'COSAM'").delete_all
    end
end
4

2 回答 2

1

Paper trail Gem 使用版本表,您的代码在更新时看起来像它正在尝试调用 paper-trail 回调,并且版本表仍未迁移必须在以后的迁移中存在。我希望这已经给出了想法,如果可能的话,您可以首先找到并迁移纸迹迁移。

于 2018-06-19T09:08:56.763 回答
0

rails5 或更高版本中,您应该在每次迁移中添加 rails 版本。所以我建议你添加下面添加的版本并尝试rails:db:migrate再次运行。

文件:20180410074207_sample_migration.rb

class SampleMigration < ActiveRecord::Migration[5.0]
    ...
end
于 2018-06-18T17:50:10.600 回答