我跑:
rails 生成迁移 AddHidemsgColumnToPublishers hide_msg:boolean
并创建了下一个文件:
class AddHidemsgColumnToPublishers < ActiveRecord::Migration
def change
add_column :publishers, :hide_msg, :boolean
end
end
我想将默认值设置为hide_msg
false。
所以我尝试了:
rails 生成迁移 add_default_value_to_hide_msg
class AddDefaultValueToHideMsg < ActiveRecord::Migration
def up
change_column :publishers, :hide_msg, :boolean, :default => false
end
def down
change_column :publishers, :hide_msg, :boolean, :default => nil
end
end
但我得到了错误:
rake db:migrate
== AddHidemsgColumnToPublishers: migrating ===================================
-- add_column(:publishers, :hide_msg, :boolean, {:default=>false})
rake aborted!
An error has occurred, this and all later migrations canceled:
PG::Error: ERROR: column "hide_msg" of relation "publishers" already exists
: ALTER TABLE "publishers" ADD COLUMN "hide_msg" boolean DEFAULT 'f'