diff --git a/lib/strong_migrations/safe_methods.rb b/lib/strong_migrations/safe_methods.rb index e756ba33..d7379d7e 100644 --- a/lib/strong_migrations/safe_methods.rb +++ b/lib/strong_migrations/safe_methods.rb @@ -44,12 +44,11 @@ def safe_add_reference(table, reference, *args, **options) end def safe_add_foreign_key(from_table, to_table, *args, **options) - validate_options = options.slice(:column, :name) - @migration.reversible do |dir| dir.up do @migration.add_foreign_key(from_table, to_table, *args, **options.merge(validate: false)) disable_transaction + validate_options = options.slice(:column, :name) if ActiveRecord::VERSION::MAJOR >= 6 @migration.validate_foreign_key(from_table, to_table, **validate_options) else @@ -57,10 +56,11 @@ def safe_add_foreign_key(from_table, to_table, *args, **options) end end dir.down do + remove_options = options.slice(:column, :name) if ActiveRecord::VERSION::MAJOR >= 6 - @migration.remove_foreign_key(from_table, to_table, **validate_options) + @migration.remove_foreign_key(from_table, to_table, **remove_options) else - @migration.remove_foreign_key(from_table, validate_options.any? ? validate_options : to_table) + @migration.remove_foreign_key(from_table, remove_options.any? ? remove_options : to_table) end end end