{"id":"8f64d859efcfc9d4","repo":"laravel/framework","slug":"this-database-driver-requires-a-type-see-the-virt","errorCode":null,"errorMessage":"This database driver requires a type, see the virtualAs / storedAs modifiers.","messagePattern":"This database driver requires a type, see the virtualAs / storedAs modifiers\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php","lineNumber":1186,"sourceCode":"     * @param  \\Illuminate\\Support\\Fluent  $column\n     * @return string\n     */\n    protected function typeGeography(Fluent $column)\n    {\n        return $this->typeGeometry($column);\n    }\n\n    /**\n     * Create the column definition for a generated, computed column type.\n     *\n     * @param  \\Illuminate\\Support\\Fluent  $column\n     * @return void\n     *\n     * @throws \\RuntimeException\n     */\n    protected function typeComputed(Fluent $column)\n    {\n        throw new RuntimeException('This database driver requires a type, see the virtualAs / storedAs modifiers.');\n    }\n\n    /**\n     * Create the column definition for a vector type.\n     *\n     * @param  \\Illuminate\\Support\\Fluent  $column\n     * @return string\n     */\n    protected function typeVector(Fluent $column)\n    {\n        return isset($column->dimensions) && $column->dimensions !== ''\n            ? \"vector({$column->dimensions})\"\n            : 'vector';\n    }\n\n    /**\n     * Get the SQL for a generated virtual column modifier.\n     *","sourceCodeStart":1168,"sourceCodeEnd":1204,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php#L1168-L1204","documentation":"MySQL's typeComputed() throws because MySQL has no standalone 'computed' SQL column type. Computed/virtual columns in MySQL are defined by attaching a virtualAs() or storedAs() expression to a real underlying type (e.g. INTEGER, VARCHAR). Throwing here signals that the developer asked for a computed column without specifying its base type.","triggerScenarios":"Calling $table->computed('full_name') directly on a MySQL/MariaDB connection. The correct shape is $table->string('full_name')->virtualAs('concat(first_name, last_name)') or ->storedAs(...). Using the bare 'computed' pseudo-type only works on SQL Server / Postgres.","commonSituations":"Porting a SQL Server migration (where 'computed' is valid) to MySQL; misunderstanding the API after reading cross-driver docs; auto-generated migrations from a tool that emits a generic computed type.","solutions":["Replace $table->computed($expr) with a concrete base type plus the modifier: $table->string('col')->virtualAs($expr) (not persisted) or ->storedAs($expr) (persisted).","If you only need a virtual expression, ensure the base type matches the expression's result type so MySQL can store/represent it.","Switch the table to a driver that supports the computed type natively (sqlsrv) if you cannot rewrite the column."],"exampleFix":"// before\n$table->computed('full_name');\n\n// after (MySQL)\n$table->string('full_name')\n      ->virtualAs('concat(first_name, \" \", last_name)');\n// or persisted:\n$table->string('full_name')\n      ->storedAs('concat(first_name, \" \", last_name)');","handlingStrategy":"validation","validationCode":"// Use a base type + modifier instead of the 'computed' pseudo-type\n// (validation is by construction: never call $table->computed() on MySQL)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["On MySQL/MariaDB always pair a concrete type with virtualAs()/storedAs().","Reserve $table->computed() for SQL Server.","Lint migrations for bare computed() usage before deploying."],"tags":["database","schema","mysql","migrations","generated-columns"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}