Removing a foreign key with Matthuhiggins foreign_key?

I have no problem adding a foreign key constraint with this stone:

http://github.com/matthuhiggins/foreigner

However, I cannot delete 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

Can anyone help me here.

Thank.

+3
source share
2 answers

This is the last thing I can think of.

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

OLD ONE

They should work :)

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

or

remove_foreign_key('threads', 'user_id')

or

remove_foreign_key(:threads, :user_id)

Peter

+6
source

The best decision

remove_foreign_key :threads, :users

However, the following should also work:

remove_foreign_key :threads, :column => :user_id

If this is not the case, indicate the error in my library.

+4
source

Source: https://habr.com/ru/post/1757515/


All Articles