2014-07-14 3 views
0

다음 두 마이그레이션을 시도합니다. 두 개의 새 열을 추가 한 다음 모든 레코드를 업데이트하여 새 기본값을 갖습니다. 그러나 슬프게도 이것은 의도 한대로 작동하지 않습니다. 대신 내가 오류 얻을 : what I have read에 따르면 undefined method 'fetch' for :boolean:Symbol마이그레이션이 작동하지 않습니다. 정의되지 않은 메소드`fetch '

class AlterPostsTableAddPublishedAndSaved < ActiveRecord::Migration 
    class Post < ActiveRecord::Base 
    end 

    def change 
    add_column :posts, :saved, :published, :boolean, :default => 0 
    Post.reset_column_information 
    reversible do |dir| 
     dir.up { Post.update_all saved: false, published: true } 
    end 
    end 
end 

을, 내가 올바른 방법으로 이것에 대해 갈거야 생각합니다. 어떤 사람이 약간의 빛을 비출 수 있었는지

답변

2

이것은 두 단계로 수행되어야하며 0은 부울 값이 아니며 true 또는 false를 사용해야합니다.

add_column :posts, :saved, :boolean, default: false 
add_column :posts, :published, :boolean, default: false 
관련 문제