Fixed issue #1261 - Adding foreign keys for inconsistent PG tables breaks update.
This commit is contained in:
parent
577c8b7995
commit
5f17ceb48a
1 changed files with 8 additions and 4 deletions
|
@ -1,4 +1,6 @@
|
|||
class ForeignKeys < ActiveRecord::Migration
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
|
||||
# return if it's a new setup
|
||||
|
@ -217,10 +219,12 @@ class ForeignKeys < ActiveRecord::Migration
|
|||
]
|
||||
|
||||
foreign_keys.each do |foreign_key|
|
||||
begin
|
||||
ActiveRecord::Migration.add_foreign_key(*foreign_key)
|
||||
rescue => e
|
||||
Rails.logger.error "Inconsistent data status detected while adding foreign key '#{foreign_key.inspect}': #{e.message}"
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
add_foreign_key(*foreign_key)
|
||||
rescue => e
|
||||
Rails.logger.error "Inconsistent data status detected while adding foreign key '#{foreign_key.inspect}': #{e.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue