I have already existing foreign key in database created this way:
class CreateUser < ActiveRecord::Migration
def change
create_table do ... end
add_foreign_key :users, :admins, column: :admin_id
end
end
but forgot to add on_delete: :nullify
. Migration is already pushed & used on production. I want to add new migration which will add cascale deleting for this PK constraint. How to achieve that?
You can remove and add foreign key in next migration:
class ChangeForgeinKeyOnUsersTable < ActiveRecord::Migration[5.0]
def change
remove_foreign_key :users, column: :admin_id
add_foreign_key :users, :admins, column: :admin_id, on_delete: :nullify
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With