Changing Tables
suggest changeIf 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_atremoves the columnordered_atfrom the tableorders.t.string :skew_numberadds a new string-type column namedskew_numberin theorderstable.t.index :skew_numberadds an index on theskew_numbercolumn in theorderstable.t.rename :location, :staterenames thelocationcolumn in theorderstable tostate.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents