class AddDataForMembers < ActiveRecord::Migration def change StudentsForCourse.all.each do |stu| if Member.where(:user_id => stu.student_id, :course_id => stu.course_id).first.nil? mem = Member.new(:user_id => stu.student_id, :course_id => stu.course_id, :course_group_id => 0, :project_id => -1, :mail_notification => 0, :role_ids => [10]) mem.save! end end end end