0

Using Rails 4, I have a column (page_id), and I need to force it to remove all data that's currently in the database column (it's in dev, so I don't care about anything that database right now).

My migration looks like this:

change_column :sections, :page_id, :uuid

(I'm migrating away from integers for Pages)

How do I use change_column and delete all the data that's currently in my database? Or do I need to do a remove_column and then an add_column that's set up correctly?

jrg
  • 731
  • 1
  • 17
  • 34
  • I think you might be best suited with a `remove_column` and `add_column`. The `change_column` is useful to change `column_name` and `column_type`. http://edgeguides.rubyonrails.org/active_record_migrations.html#changing-columns – oreoluwa Jun 13 '16 at 17:24
  • http://stackoverflow.com/questions/25681599/rails-4-migrate-table-id-to-uuid – itsnikolay Jun 13 '16 at 18:45

1 Answers1

0

Remove then add the column seems the best option. But you can change the column and then update all the records with something like Section.update_all({:uuid => nil})

Ronan Lopes
  • 3,320
  • 4
  • 25
  • 51