create_table :widgets do |t|
t.string :form_data, :default=>"" :null=>false
t.timestamps
end
A few months went by and we decided to upgrade from 1.2.6 to 2.1.0 but it required us to change from strings to text fields. The migration script looked like this:
change_column(:widgets, :form_data, :text, :default=>"")
In Rails 2.1.2 the change_column function retained its nullability unless you explicitly requested it, however in 2.1.0 it would always redefine it to the defaul null => true. Tailing the logs confirmed this subtle difference:
2.1.0 =>
ALTER TABLE widgets CHANGE COLUMN form_data text DEFAULT '' NOT NULL
2.1.2 =>
ALTER TABLE widgets CHANGE COLUMN form_data text DEFAULT ''
We then had to create another migration so that we would be in sync with our production database:
change_column(:widgets, :form_data, :text, {:default=>"", :null => true })
Annoying but true.
No comments:
Post a Comment