To add a column to an existing table on Ruby on Rails you would need to create a rails command to generate that migration. Also, there will be an opportunity to name your migration under the context of what you need.
rails generate migration AddImageColumnToListings image:string
This commands adds the image column to your listings table with the string content. A file would be added to your migrate folder.
class AddImageColumnToListings < ActiveRecord::Migration[6.1]
def change
add_column :listings, :image, :string
end
end
At this point you can make any changes to the files before running
rails db:migrate
Top comments (0)