Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rt0611's avatar

rt0611 wrote a reply+100 XP

5mos ago

I inherited a legacy schema where some tables live in a separate admin database, while the app’s transactional data lives in the default database.

rt0611's avatar

rt0611 started a new conversation+100 XP

5mos ago

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