Does this version work for you?
class AddDeletedAtToOptions < ActiveRecord::Migration
class Option < ActiveRecord::Base; end
# Add `deleted_at` column, set to Time.now if `is_deleted` is true,
# then remove `is_deleted`:
add_column(:options, :deleted_at, :timestamp, :default => nil)
say "IN TABLE option: Setting `deleted_at` to now if `is_deleted`
Option.update_all(['deleted_at = ?', Time.now], ['is_deleted
= ?', true])
# Add `is_deleted` column, set to true if `deleted_at` isn't NULL,
# then remove `deleted_at`
add_column(:options, :is_deleted, :boolean, :default =>
false, :null => false)
say "IN TABLE option: Setting `is_deleted` to true if
`deleted_at` set." do
Option.update_all(['is_deleted = ?', true], 'deleted_at IS NOT
Sorry, I haven't tried it, but it is similar to some of the migrations
that I've had to created.
Rob Biedenharn http://agileconsultingllc.com
In case anyone finds this which Googling the same problem (like I did)
this blog post has the answer:
Essentially you need to call reset_column_information on your model. For
add_column 'my_models', 'new_column'
my_model = MyModel.first
my_model.new_column = 'this will save'
Posted via http://www.ruby-forum.com/.