class CreateComments < ActiveRecord::Migration[6.0]
def change
create_table :comments do |t|
t.text :body
t.references :commentable, polymorphic: true
t.timestamps
end
end
end
- Create a new migration file using the
rails generate migration
command. - In the migration file, define a new table for comments with a text column for the body of the comment.
- Add a
references
column named commentable
to the comments table, making it polymorphic using polymorphic: true
. - Include timestamps for tracking creation and update times in the comments table.
- Run the migration using the
rails db:migrate
command to apply the changes to the database.
```