Running php artisan migrate returns error from sqlite: "no such table: pragma_compile_options"

184 views Asked by At

I was following this Laravel bootcamp:

https://bootcamp.laravel.com/inertia/installation

I installed Laravel and changed DB_CONNECTION to sqlite as directed.

However when I tried to complete the installation of Laravel Breeze by running migrations, I received an exception from sqlite.

Here is the output from the command:

$ php artisan migrate

   Illuminate\Database\QueryException

  SQLSTATE[HY000]: General error: 1 no such table: pragma_compile_options (Connection: sqlite, SQL: select exists (select 1 from pragma_compile_options where compile_options = 'ENABLE_DBSTAT_VTAB') as enabled)

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:822
    818▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    819▕                 );
    820▕             }
    821▕
  ➜ 822▕             throw new QueryException(
    823▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    824▕             );
    825▕         }
    826▕     }

      +30 vendor frames

  31  artisan:35
      Illuminate\Foundation\Console\Kernel::handle()

The file database/database.sqlite is created but is empty.

I tried to google the error message but nothing turned up.

Here is the sqlite version used:

$ sqlite3 --version
3.32.3 2020-06-18 14:00:33 7ebdfa80be8e8e73324b8d66b3460222eb74c7e9dfd655b48d6ca7e1933cc8fd

Here is the version of Laravel used:

$ php artisan --version
Laravel Framework 10.34.2

Is there something I can do to continue the tutorial using sqlite as the database?

1

There are 1 answers

2
Top-Master On

Update

It seems pragma_compile_options is a built-in table of SQLite.

Meaning, you not having such table means that, your Laravel's DB connection is configured for SQLite engine, but your actual database engine is something else.

  • If that's the cause, fix your configs to use right engine, maybe try MySQL.

Another possible cause; maybe Laravel does not support your SQLite version.

  • If that's the cause, try upgrading Laravel and/or downgrading SQLite.

Example configs

In my ./config/database.php file, I have something like:

return [
    'connections' => [
        'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

        // ...
    ],
    
    // ...
];

Old answer

Try dropping/removing all tables:

php artisan db:wipe

Then repeat:

php artisan migrate

Finally ensure DB has initial data, like:

php artisan db:seed

Done!