아래의 마이그레이션 파일은 오류없이 성공적으로 실행되며 열조차 생성되지만 이상하게 데이터가 업데이트되지 않습니다.이상한 레일 마이그레이션 동작 - 마이그레이션은 성공했지만 여전히 데이터는 채워지지 않습니다.
코드를 레일즈 콘솔에서 실행하면 (생성 열은 무시함) 매우 훌륭하게 작동합니다. 모든 설명 :
class AddSubjectListToTestType < ActiveRecord::Migration
def change
add_column :test_types, :subject_list, :integer, array:true, default: []
type_hash = {
"NEET" => ["Physics" , "Chemistry", "Botany", "Zoology"],
"JEE" => ["Physics", "Chemistry", "Mathematics"],
"CET" => ["Physics", "Chemistry", "Mathematics"]
}
TestType.all.each do |test_type|
type_hash[test_type.name].each do |subject|
test_type.subject_list << Subject.find_by_name(subject).id
end
test_type.save
end
end
end
모든 'test_types'를 반복하므로 내 첫 질문은 데이터베이스에 얼마나 많은 것들이 있습니까? BTW 마이그레이션을 모델과 결합하는 것이 좋지 않습니다. 모델은 변경 될 수 있으며 마이그레이션은 수행되지 않습니다. –
테스트 유형에 3 개의 레코드 만 있고 세 개의 레코드 모두 question_count_per_subject 키에 나열된 이름을가집니다. –