开发者

Without foreign key in rails

开发者 https://www.devze.com 2023-02-22 18:39 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消