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

SaschaWaitz's avatar

SaschaWaitz started a new conversation+100 XP

4mos ago

Laravel 12: Pest and multiple databases

Hello everyone,

I have come across a problem. I have two databases a main database and another database for another project. I can migrate in both without any problems and also the tests for the main database are working like they should be working. But as soon as I test a model which uses the second database the test fails and tells me that the table of the model is not existent.

I have added to every model and migration file the

protected $connection='db1'; ​

I have also changed the testing env to a sqlite database. When I use a real connection to a mysql server nothing works anymore. In that case I get the error that the database was not created and the tests for both abort.

Has anyone a tip for me what I can do?

Thanks and greetings, Sascha