TH Afridi
TH Afridi

Reputation: 432

want to change columntype in a table through migration

Hi i have a table in which there are two columns from and to of type datatime i want to change the datatype from datetime to date. i dont know the exact command for chagning column type in migrations like rails g

Upvotes: 3

Views: 4397

Answers (2)

Syed Raza
Syed Raza

Reputation: 1098

From the command line, run:

rails generate migration change_data_type_for_table_column

Write your migration as:

change_table :table do |t|  
  t.change :column, :type 
end

Upvotes: 8

Simone Carletti
Simone Carletti

Reputation: 176552

Use change_column.

change_column(:table, :column, :date)

Upvotes: 2

Related Questions