私は次のコードで私のポストのテーブルへのユーザーの参照を追加しようとしています:未定義のメソッド「add_reference」
class AddUserIdToPosts < ActiveRecord::Migration
def change
add_reference :posts, :user, index: true
end
end
をしかし、私はエラーメッセージを受信しました:
undefined method 'add_reference'
誰もが知っていますこれを解決するには?
私はあなたがそれをあなたが投稿の方法を行うことができますので、
class AddUserIdToPosts < ActiveRecord::Migration
def change
add_column :posts, :user_id, :integer
add_index :posts, :user_id
end
end
のみのRails 4のようにあなたがそれを行う必要があります3 RailsではRailsの3.2.13
すべきですか? http://stackoverflow.com/questions/4954969/rails-3-migrations-adding-reference-column – dax