Create a join table

suggest change

To create a join table between students and courses, run the command:

$ rails g migration CreateJoinTableStudentCourse student course

This will generate the following migration:

class CreateJoinTableStudentCourse < ActiveRecord::Migration[5.0]
  def change
    create_join_table :students, :courses do |t|
      # t.index [:student_id, :course_id]
      # t.index [:course_id, :student_id]
    end
  end
end

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


ActiveRecord migrations:
*Create a join table

Table Of Contents
4ActiveRecord migrations
55CSV