Why are you using two databases?
Testing with Multiple DB Connections
Version 11.31.
I have two MySQL connections; one table on connection A references a parent table on connection B. When I run tests with both connections in transactions (using DatabaseTransactions), inserting the child row blocks until MySQL throws Error: 1205 Lock wait timeout exceeded.
I’d prefer to use RefreshDatabase so both databases roll back after each test, but running RefreshDatabase triggers migrate:fresh, which fails because the tables already exist—we migrate them ahead of time. Is there a way to
(a) run only pending migrations for both connections without migrate:fresh, and (b) roll back both connections despite the cross-DB FK?
<?php
namespace Tests;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use DatabaseTransactions;
protected function connectionsToTransact(): array
{
return [
config('database.default'),
config('app.admin_connection_name'),
];
}
}
This is what I currently have
Please or to participate in this conversation.