我想部署一个临时服务器,我使用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),但我想知道替代解决方案
我认为这个解决方案
(抱歉,我的英语不好)
编辑: - 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
答案 0 :(得分:1)
Paper trail Gem使用版本表,您的代码在更新时看起来像是在尝试调用paper-trail回调,并且在以后的迁移中仍然不会迁移仍未迁移的版本表。我希望这已经给出了想法,如果可能的话,您可以先找到并迁移纸质跟踪迁移。
答案 1 :(得分:0)
在rails
5或更高版本中,您应该在每次迁移中添加rails版本。因此,我建议您添加下面添加的版本,然后再次尝试运行rails:db:migrate
。
档案: 20180410074207_sample_migration.rb
class SampleMigration < ActiveRecord::Migration[5.0]
...
end