Search code examples
ruby-on-railsrubyactiverecorddatescaffolding

Command to Change DB Column in Ruby on Rails


Is there a quick console command I can run to change the type I have for an object? It's currently a Ruby Date type, but I would like it to be a Ruby Time type.

I started with this scaffold command:

$ rails generate scaffold Post title:string content:text postdate:date

But wish I would have done the following:

$ rails generate scaffold Post title:string content:text postdate:time

Is there a command and can run to make the update?


Solution

  • Sometimes you have to write some actual code, even in Rails. Try creating migration and then using change_column method. Something like

    change_column :my_table, :my_column, :new_type
    

    You put this in your db migration file, not in shell.