2

I am trying to migrate some datetime columns in MySQL to timestamp type. In ActiveRecord migration I have:

change_column(:oe_tags, :created_on, :timestamp)

however the sql it generates is

ALTER TABLE `oe_tags` CHANGE `created_on` `created_on` datetime DEFAULT NULL

which is obviously NOT a timestamp type, but rather datetime (which it already is). How do I get an alteration to timestamp? According to the documentation :timestamp is a valid symbol.

Edit: Perhaps I did not make myself clear (apologies). I would like to know the proper change_column specification in ActiveRecord migration in Rails. I already KNOW the proper SQL I expect. How to achieve it via an ActiveRecord Migration is the question.

TJChambers
  • 1,489
  • 1
  • 18
  • 28
  • Maybe you'll find some answers here http://stackoverflow.com/questions/9227784/making-activerecord-rails-use-actual-mysql-timestamp-columns, it's very similar to your question – AdrienK Dec 19 '12 at 13:18
  • Thanks @AdrienK - that is exactly what I needed. Not sure how you located that - I searched first and didn't see it. – TJChambers Dec 19 '12 at 13:26

1 Answers1

-2

Try the modify keyword ::

ALTER TABLE `oe_tags` MODIFY `created_on` datetime DEFAULT NULL
Sashi Kant
  • 13,277
  • 9
  • 44
  • 71