ahmeda's avatar

General error: 1 no such table: fresh.admins in Laravel Unit Test

I have created the following unit test:

<?php

namespace Tests\Feature\Auth;

use Tests\TestCase;
use Asu\Domain\Admins\Admin;
use Illuminate\Foundation\Testing\RefreshDatabase;

class LoginAdminTest extends TestCase
{
    use RefreshDatabase;

    /** @test */
    public function admin_can_login_and_see_his_token()
    {
        $admin = Admin::factory()->create();

        dd($admin);

    }
 }

When I run it, I get:

SQLSTATE[HY000]: General error: 1 no such table: fresh.admins

However, in tinker, the seed is just working fine, and I have used both RefreshDatabase & DatabaseMigrations and still got the same error.

⭕️ Note: in my app I do not have migration I just connect to database that already exist somewhere.

0 likes
3 replies
tykus's avatar
tykus
Best Answer
Level 104

in my app I do not have migration I just connect to database that already exist somewhere.

Use the DatabaseTransactions trait in that case, not RefreshDatabase.

ahmeda's avatar

I used it, but still get this error!!

tykus's avatar

Does the database you are connecting to have an admins table?

Are you connecting to the correct database - usually defined in the phpunit.xml file under server variables.

Please or to participate in this conversation.