Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test Error: Base table or view not found: 1146 Table 'testing.users' doesn't exist

I make this simple test:

public function test_my_awesome_test()
{
    $user = User::find(1);
    $response = $this->actingAs($user)->get('/awesome/test');

    $response->assertStatus(200);
}

But after run test it's display me error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'testing.users' doesn't exist (SQL: select * from users where users.id = 1 limit 1)

I had this same error if I needed to print some data from database. This tables exist and website works correctly. Who know where is problem?

like image 432
wtsuport Avatar asked Mar 06 '26 04:03

wtsuport


1 Answers

According to the Laravel documentation, Sail overrides the DB name you defined in the .env file when you run the tests. You need to remove the following line from your phpunit.xml file:

<env name="DB_DATABASE" value="testing"/>
like image 172
Onur Uslu Avatar answered Mar 08 '26 20:03

Onur Uslu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!