diff --git a/activerecord/lib/active_record/railties/console_sandbox.rb b/activerecord/lib/active_record/railties/console_sandbox.rb index 604a220303..1a04950898 100644 --- a/activerecord/lib/active_record/railties/console_sandbox.rb +++ b/activerecord/lib/active_record/railties/console_sandbox.rb @@ -1,5 +1,7 @@ ActiveRecord::Base.connection.begin_transaction(joinable: false) at_exit do - ActiveRecord::Base.connection.rollback_transaction + if ActiveRecord::Base.connection.transaction_open? + ActiveRecord::Base.connection.rollback_transaction + end end