If you have created a table with some wrong schema, then the easiest way to change the columns and their properties is change_table. Review the following example:
change_table :orders do |t|
t.remove :ordered_at # removes column ordered_at
t.string :skew_number # adds a new column
t.index :skew_number #creates an index
t.rename :location, :state #renames location column to state
end
The above migration changes a table orders. Here is a line-by-line description of the changes:
t.remove :ordered_at removes the column ordered_at from the table orders.t.string :skew_number adds a new string-type column named skew_number in the orders table.t.index :skew_number adds an index on the skew_number column in the orders table.t.rename :location, :state renames the location column in the orders table to state.