diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index bee74dc33d..38b1c31376 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -409,13 +409,14 @@ module ActiveRecord def alter_table(table_name, options = {}) altered_table_name = "a#{table_name}" + options_to_restore = { foreign_keys: foreign_keys(table_name) } caller = lambda { |definition| yield definition if block_given? } transaction do disable_referential_integrity do move_table(table_name, altered_table_name, options.merge(temporary: true)) - move_table(altered_table_name, table_name, &caller) + move_table(altered_table_name, table_name, options_to_restore, &caller) end end end @@ -446,6 +447,13 @@ module ActiveRecord primary_key: column_name == from_primary_key ) end + + if options[:foreign_keys] + options[:foreign_keys].each do |fk| + @definition.foreign_key(fk.to_table, fk.options) + end + end + yield @definition if block_given? end copy_table_indexes(from, to, options[:rename] || {}) |