I need to change the data type of a column in a DB from :string to :decimal. All values are in the following format: "129.99", so converting them should not raise any errors.
To do so I wrote the following migration:
def change
change_column :my_table, :target_column, :decimal
end
When I execute this it shows me the following error together with a hint on how to fix it:
PG::DatatypeMismatch: ERROR: column "target_column" cannot be cast automatically to type numeric
HINT: You might need to specify "USING target_column::numeric".
However, I can't seem to find any documentation about how to do this, so the hint doesn't really help me.
Whats the best way to perform this migration?