I have an active record model:
class Person < ActiveRecord::Base
serialize :tags, Array
end
and in the migration the tags column is declared as
t.text :tags, :default => []
but when I try to create a person
Person.new
I get the error
ActiveRecord::SerializationTypeMismatch: added was supposed to be a Array, but was a String
How do I set the default to be an empty array in the migration?
NB: I know I could do this using after_initialize but I prefer to set defaults in migrations
stringcolumn which I serialize asArray. An empty array would result in an empty string"". The problem was that the column hadnull: falseandserializewants to serialize[]asnil. When it cannot, it uses"", but then it can't deserialize correctly.