Without foreign key in rails
i want to add in my 开发者_运维百科migration field parent_id, but it isn't FK, how i can say it to rails? Thanks, i read about this, but forgot and now can't find it..
I think you can just add it in the same way as any other field:
for example
rails g migration add_parent_id_to_foo parent_id:string
or
class AddParentIdToFoo < ActiveRecord::Migration
def self.up
add_column :foos, :parent_id, :string (or integer or whatever)
end
def self.down
remove_column :foos, :parent_id
end
end
精彩评论