laravel/framework · error · RuntimeException

This database driver requires a type, see the virtualAs /…

Error message

This database driver requires a type, see the virtualAs / storedAs modifiers.

What it means

SQLiteGrammar::typeComputed mirrors the MySQL variant: SQLite does not expose a standalone COMPUTED type. Generated columns must be declared with a concrete base type plus a virtualAs (not supported on old SQLite) or storedAs expression. Reaching typeComputed means a column was created with type 'computed' and no expression/type, which SQLite cannot map.

Solutions

  1. Declare a real base type with a storedAs expression: $table->integer('total')->storedAs('a + b') (requires SQLite >= 3.31 for generated columns).
  2. Drop the computed column on SQLite and compute the value in application code or a view.
  3. Gate the column by driver and skip it on SQLite in tests.

Example fix

// before
$table->computed('total');

// after
$table->integer('total')->storedAs('price * qty');
Defensive patterns

Strategy: validation

Validate before calling

// never emit 'computed' on SQLite; use a base type + storedAs (SQLite >= 3.31)
$table->integer('total')->storedAs('price * qty');
// or skip the column on SQLite:
use Illuminate\Support\Facades\DB;
if (DB::connection()->getDriverName() !== 'sqlite') {
    $table->integer('total')->storedAs('price * qty');
}

Prevention

When it happens

Trigger: Declaring $table->computed(...) or a custom Fluent column with type 'computed' on a SQLite connection without setting virtualAs/storedAs and a base type.

Common situations: Cross-driver migrations using a COMPUTED column abstraction that works on SQL Server but not SQLite; testing on SQLite while production uses SQL Server's COMPUTED; upgrading a package that introduced a computed column.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/6ffa0100d8c9f880. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php:1084

     * @param  \Illuminate\Support\Fluent  $column
     * @return string
     */
    protected function typeGeography(Fluent $column)
    {
        return $this->typeGeometry($column);
    }

    /**
     * Create the column definition for a generated, computed column type.
     *
     * @param  \Illuminate\Support\Fluent  $column
     * @return void
     *
     * @throws \RuntimeException
     */
    protected function typeComputed(Fluent $column)
    {
        throw new RuntimeException('This database driver requires a type, see the virtualAs / storedAs modifiers.');
    }

    /**
     * Get the SQL for a generated virtual column modifier.
     *
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
     * @param  \Illuminate\Support\Fluent  $column
     * @return string|null
     */
    protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
    {
        if (! is_null($virtualAs = $column->virtualAsJson)) {
            if ($this->isJsonSelector($virtualAs)) {
                $virtualAs = $this->wrapJsonSelector($virtualAs);
            }

            return " as ({$virtualAs})";
        }

View on GitHub (pinned to e0f6eb3518)