开发者

How to alter columns with ActiveRecord in Rails?

I'm new to ActiveRecord. I realized that I had forgotten to add a default value for a column in one of my tables. I want to create a migration to fix this, but I can't figure out how. Is there an alter_column method that you can call during migrations? If not, how can I do it?

EDIT: I just tried using change_column, but this causes an error like this:

-- change_column(:carts, :quantity, :integer, {:default=>1}) -> 0.0097s rake aborted! An error has occurred, this and all later migr开发者_高级运维ations canceled:

wrong number of arguments (0 for 1)


you can simply do a change_table:

change_table(:tablename) do |t|
   t.change :name, :string, :default => "something"
end

edit: in this case you can use change_column_default

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜