Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, :users)
  end

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

Could someone help me out here.

Thanks.

like image 332
never_had_a_name Avatar asked Mar 24 '26 10:03

never_had_a_name


1 Answers

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

like image 73
praethorian Avatar answered Mar 26 '26 13:03

praethorian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!