开发者

Removing foreign key using Matthuhiggins foreign_key?

I have no problem with adding the foreign key constraint with this gem:

http://github.com/matthuhiggins/foreigner

However, I cannot remove the foreign key.

class ForeignKeys < ActiveRecord::Migration
  def self.up
    add_foreign_key(:threads开发者_JS百科, :users)
  end

  def self.down
    remove_foreign_key(:threads, :column => :user_id)
  end
end

Could someone help me out here.

Thanks.


This the last thing I can think of.

def self.down
    execute 'ALTER TABLE threads DROP FOREIGN KEY user_id'
end

OLD ONE

These should work :)

remove_foreign_key :threads, { :column => :user_id }

or

remove_foreign_key('threads', 'user_id')

or

remove_foreign_key(:threads, :user_id)

Petr


The best solution is

remove_foreign_key :threads, :users

However, the following should have also worked:

remove_foreign_key :threads, :column => :user_id

If it didn't, file a bug on my library.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜