Lake, thanks for your answer. However, my migration does exactly this
(change_column). The problem is that I do not want a default value on
the resulting column.
To continue with the example you provided, if I do:
change_column :books, :name, :string, :default => "Lake"
I am making the default for the column be "Lake", which is not the
intended result. Ideally, I would simply say:
change_column :books, :name, :string, :null => false
In which case the name column in the books table is not nullable (this
is what I want). My original column was nullable, and had a default
value of NULL, but when this migration is ran, the resulting column
has a default value of "NULL" as a string, which is what I want to
If I try
change_column :books, :name, :string, :null => false, :default => nil
I end up with the same result (default value of "NULL").
How can I get rid of the default value for this table all together?
One possible solution is to do:
add_column :books, :temp_name, :string, :null =3D> false
#store names on new temp_name column
Book.find(:all).each do |b|
b.name.nil? b.temp_name => b.name : b.temp_name = 'Unknown'
remove_column :books, :name
rename_column :books, :temp_name, :name
I'm wondering if there is an easier way though...
PS: What happened to this group for the better part of the day? It was
inaccessible for a while...