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

MySQL's grammar implements typeComputed() as a hard failure. MySQL does not have a standalone COMPUTED column type; a generated column must be declared with a concrete base type together with a virtualAs (VIRTUAL) or storedAs (STORED) expression modifier. Reaching typeComputed means the column was created with ->computed() without an underlying type and without a generation expression.

Solutions

  1. Use the intended base type plus a generation expression, e.g. $table->integer('total')->storedAs('a + b') or $table->string('upper_name')->virtualAs('UPPER(name)').
  2. If you only need an expression, drop the explicit type call and rely on ->virtualAs() / ->storedAs() which set the type automatically.
  3. Audit custom ColumnDefinition builders to ensure they never emit type === 'computed' on MySQL.

Example fix

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

// after
$table->integer('total')->storedAs('price * qty');
// or
$table->string('full_name')->virtualAs('CONCAT(first_name, " ", last_name)');
Defensive patterns

Strategy: validation

Validate before calling

// never emit type 'computed' directly on MySQL; always pair a base type with a generation expression
$table->integer('total')->storedAs('price * qty');
// or
$table->string('full_name')->virtualAs('CONCAT(first, last)');

Type guard

function generatedColumnIsTyped(\Illuminate\Support\Fluent $c): bool
{
    return $c->type !== 'computed'
        && (! empty($c->virtualAs) || ! empty($c->storedAs));
}

Prevention

When it happens

Trigger: Declaring $table->computed(...) or setting the Fluent 'computed' type directly on a MySQL blueprint without also setting virtualAs/storedAs and a real column type.

Common situations: Porting a migration from another framework that has a native COMPUTED type; using a column-definition helper that emits type 'computed'; hand-crafting a Fluent column instead of using ->virtualAs() / ->storedAs().

Related errors


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

Appendix: source

Thrown at src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php:1186

     * @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.');
    }

    /**
     * Create the column definition for a vector type.
     *
     * @param  \Illuminate\Support\Fluent  $column
     * @return string
     */
    protected function typeVector(Fluent $column)
    {
        return isset($column->dimensions) && $column->dimensions !== ''
            ? "vector({$column->dimensions})"
            : 'vector';
    }

    /**
     * Get the SQL for a generated virtual column modifier.
     *

View on GitHub (pinned to e0f6eb3518)