views:

32

answers:

1

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 migrations canceled:

wrong number of arguments (0 for 1)

+1  A: 

you can simply do a change_table:

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

edit: in this case you can use change_column_default

KARASZI István
That doesn't work in Rails 3. It gives me this error: 'SQLite3::SQLException: duplicate column name: quantity: ALTER TABLE "carts" ADD "quantity" integer DEFAULT 1'
picardo
I almost didn't see your edit. thank you.
picardo