Is it possible to change a field that's a string to an integer without clearing the data already entered?
The current db structure for the table in question is:
create_table :people do |t| t.string :company_id
Is this possible using migrations?
I'm thinking maybe in the migration drop the old field, create a new one that's an integer - but I'm worried this will clear all of the data already entered.
Thanks,
Danny
Don't drop the column, use this
change_column :table_name, :column_name, 'integer USING CAST(column_name AS integer)'
The "hint" you got from PostgreSQL basically tells you that you need to confirm you want this to happen, and how data should be converted. To confirm the changes, use the block above in your migration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With