laravel/framework · error · RuntimeException

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

Error message

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

What it means

SQLite's typeComputed() throws because, like MySQL, SQLite has no standalone 'computed' type. SQLite generated columns are created by attaching a ->virtualAs() or ->storedAs() expression to a real base type. The throw fires when the 'computed' pseudo-type is requested directly.

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 bd6b5437e6)

Solutions

  1. Use a concrete base type with virtualAs/storedAs: $table->integer('col')->storedAs('expr').
  2. Driver-guard the 'computed' usage to drivers that support it (sqlsrv).
  3. For SQLite tests specifically, replace computed with a plain column and recompute in PHP if the expression is simple.

Example fix

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

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

Strategy: validation

Validate before calling

// On SQLite (and MySQL), use a concrete type + virtualAs/storedAs
$table->integer('total')->storedAs('price * qty');

Prevention

When it happens

Trigger: Calling $table->computed('expr') directly on a SQLite connection. Correct SQLite usage is $table->integer('col')->storedAs('expr') or ->virtualAs('expr'). Often hit when running tests on SQLite for a migration that uses the cross-driver 'computed' convenience type.

Common situations: Test suite on SQLite with migrations targeting SQL Server's computed type; auto-generated migrations emitting a generic computed column; misunderstanding the API.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/6ffa0100d8c9f880.json. Report an issue: GitHub.