Open kaorukobo opened 9 months ago
Got this error too. After specifying cleaners for primary (AR::Base) and then to secondary (some other model) DB I got AR::Base connection to wrong DB
Quick workaround is to specify cleaning strategy for primary DB to be the last:
DatabaseCleaner[:active_record, db: :secondary].strategy = :transaction
DatabaseCleaner[:active_record, db: :primary].strategy = :transaction
This will return primary DB connection to ActiveRecord::Base
Any update on this? @BoutPure's suggestion above does not solve the problem for me.
Note: I will make a pull request that follows this issue.
Summary
When we use DatabaseCleaner for a multi-database environment, the connection for "main" models (i.e., models inheriting the connection pool from ActiveRecord::Base) gets replaced with the connection for non-main models.
Reproduction
For the full reproduction code, see https://gist.github.com/kaorukobo/8dd0e5ef6c8662cc5de88aceea5043a1