1
我有這個遷移在我的Rails項目刪除列默認
class ChangeColumnDefaultOfTemp < ActiveRecord::Migration
def up
change_column_null :states, :temp, false, ''
change_column_default :states, :temp, ''
end
def down
change_column_null :states, :temp, true
change_column :states, :temp, :string, default: nil
end
end
我能夠與
change_column_null :states, :temp, true
恢復NOT NULL約束,但這個命令
change_column :states, :temp, :string, default: nil
是不是給我預期的結果
rake db:migrate
temp | character varying(255) | not null default ''::character varying
rake db:rollback
temp | character varying(255) | default NULL::character varying
-- Expected is
temp | character varying(255) |
注:尋找類似的東西,以
ALTER [ COLUMN ] column DROP DEFAULT