It's okay to make a table, but is there a way to add columns? I was worried, so I wrote it.
Type the command in the terminal.
rails g migration Add Column name To Table name Column name: Type
For example, if you want to increase only one
rails g migration AddNameToPosts name:string
If more than one
rails g migration AddColumnsToPosts name:string day:data
You can use any name for Columns in AddColumnsToPosts.
Finally,
rails db:migrate
Is OK!
I will also write how to delete the column.
rails g migration Remove Column name From table name Column name: Type
For example, if you want to reduce only one
rails g migration RemoveNameFromPosts name:string
If more than one
rails g migration RemoveColumnsFromPosts name:string day:data
Again, any name is OK for Columns in RemoveColumnsFromPosts.
Finally,
rails db:migrate
Is OK!
https://qiita.com/ITmanbow/items/2bf4dfa4d9ca705b97df It was very helpful!
Recommended Posts