Ruby on Rails - changing tables in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
- We have created a table with some wrong schema, then the easiest way to change the columns and their properties is change_table.
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
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
- Above migration changes a table orders.
line-by-line description of the changes
- t.remove :ordered_at removes the column ordered_at from the table orders.
- t.string :skew_number adding a new string-type column named skew_number in the orders table.
- t.index :skew_number adding 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.