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

alkhatib's avatar
Level 16

SQLSTATE[HY000]: General error: 1 no such table

Hello, When running tests, I'm encountering an error because a specific database table cannot be found. The error seems to occur due to a query in the AppProviderService. How can I ensure that the database is fully set up and accessible during tests to prevent this issue?

phpunit.xml

Pest.php

pest()
    ->extend(Tests\TestCase::class)
    ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
    ->in('Feature');

DashboardPanelProvider

class DashboardPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->default()
            ->id('dashboard')
            ->path(Settings::dashboardPrefix());
  }
}

test

/** @test */
it('renders successfully', function () {
    $response = $this->get(route('login'));
    $response
        ->assertSeeLivewire(Login::class)
        ->assertStatus(200);
});

error

 FAILED  Tests\Feature\Livewire\Auth\LoginTest > it renders successfully               QueryException   
  SQLSTATE[HY000]: General error: 1 no such table: settings (Connection: sqlite, SQL: select "name", "payload" from "settings" where "group" = system)

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:407
    403▕             // For select statements, we'll simply execute the query and return an array
    404▕             // of the database result set. Each element in the array will be a single
    405▕             // row from the database table, and will either be an array or objects.
    406▕             $statement = $this->prepared(
  ➜ 407▕                 $this->getPdoForSelect($useReadPdo)->prepare($query)
    408▕             );
    409▕ 
    410▕             $this->bindValues($statement, $this->prepareBindings($bindings));
    411▕ 

      +15 vendor frames 
  16  app/Services/Settings/Concerns/HasSystem.php:56
      +1 vendor frames 
  18  app/Providers/Filament/DashboardPanelProvider.php:32


  Tests:    1 failed (0 assertions)
  Duration: 7.82s

0 likes
14 replies
experimentor's avatar

@alkhatib Ideally, RefreshDatabase should migrate all tables before running the tests. If the error is saying that the table does not exist, maybe its getting dropped in some other migration. I'd run the migrations fresh on a test / local database to verify if the settings table gets generated.

I can't think of anything else ... other than maybe clearing caches before running tests.

alkhatib's avatar
Level 16

@experimentor My friend, when trying to get any table inside the provider, we get the same error. ex : User::all(); error General error: 1 no such table: users

When these two lines are disabled, the test runs correctly but the database is being emptied.

   <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>
alkhatib's avatar
Level 16

@Tray2 There are no files outside the features directory. I have only "renders successfully"

alkhatib's avatar
Level 16

@Tray2 error caused by requesting a settings table inside DashboardPanelProvider

alkhatib's avatar
Level 16

@Tray2 I used trait DatabaseMigrations . but same error

pest()
    ->extend(Tests\TestCase::class)
    ->use(Illuminate\Foundation\Testing\DatabaseMigrations::class)
    ->in('Feature');
alkhatib's avatar
Level 16

@Tray2 I am sure all tables have been migrated. The problem is not of the settings table not exists, When requesting any table inside AppProvider, We will get the same error table does not exist.

Disable fetch from settings table

class DashboardPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->default()
            // ->path(Settings::dashboardPrefix())
            ->id('dashboard');
  }
}

fetch from users table

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        dd(User::first());
  }
}

error

 FAILED  Tests\Feature\Livewire\Auth\LoginTest > it renders successfully               QueryException   
  SQLSTATE[HY000]: General error: 1 no such table: users (Connection: sqlite, SQL: select * from "users" limit 1)

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:407
    403▕             // For select statements, we'll simply execute the query and return an array
    404▕             // of the database result set. Each element in the array will be a single
    405▕             // row from the database table, and will either be an array or objects.
    406▕             $statement = $this->prepared(
  ➜ 407▕                 $this->getPdoForSelect($useReadPdo)->prepare($query)
    408▕             );
    409▕ 
    410▕             $this->bindValues($statement, $this->prepareBindings($bindings));
    411▕ 

      +14 vendor frames 
  15  app/Providers/AppServiceProvider.php:37
      +11 vendor frames 
  27  tests/TestCase.php:11


  Tests:    1 failed (0 assertions)
  Duration: 19.62s

When all fetch queries disabled then run test

/** @test */
it('Login successfully', function () {
    $user = user();
    $response = $this->json('POST', '/login', [
        Fortify::username() => $user->email,
        'password' => 'password',
    ]);
    $response->assertOk();
    $this->assertAuthenticated();
});
   PASS  Tests\Feature\Livewire\Auth\LoginTest
  ✓ it Login successfully                                                                          9.98s  

  Tests:    1 passed (2 assertions)
  Duration: 11.50s
Tray2's avatar

@alkhatib First you get

 General error: 1 no such table: settings

Then you comment out the code that fetches the settings, and then you get this.

General error: 1 no such table: users

That means that the migrations has not been ran, before you are attempting to access the tables in the database.

alkhatib's avatar
Level 16

@Tray2 That means Provider boot method executes before table creation.

experimentor's avatar
Level 25

@alkhatib Here are a few references to similar errors: https://github.com/laravel/framework/issues/25223 https://laracasts.com/discuss/channels/laravel/queryexception-general-error-1-no-such-table-categories https://laracasts.com/discuss/channels/testing/sqlstatehy000-general-error-1-no-such-table

Most of them say that the AppServiceProvider's boot method executes before table creation. Hence the error.

Hope you can find the solution in these links.

1 like

Please or to participate in this conversation.