{"record":{"id":"eb07d51e6b2cd2e6","repo":"yiisoft/yii2","slug":"sqlite-does-not-support-default-value-constraints","errorCode":null,"errorMessage":"SQLite does not support default value constraints.","messagePattern":"SQLite does not support default value constraints\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"framework/db/sqlite/Schema.php","lineNumber":205,"sourceCode":"            if (isset($createTableToken[$firstMatchIndex - 2]) && $createTableToken->matches($pattern, $firstMatchIndex - 2)) {\n                $name = $createTableToken[$firstMatchIndex - 1]->content;\n            }\n            $result[] = new CheckConstraint([\n                'name' => $name,\n                'expression' => $checkSql,\n            ]);\n        }\n\n        return $result;\n    }\n\n    /**\n     * {@inheritdoc}\n     * @throws NotSupportedException if this method is called.\n     */\n    protected function loadTableDefaultValues($tableName)\n    {\n        throw new NotSupportedException('SQLite does not support default value constraints.');\n    }\n\n    /**\n     * Creates a query builder for the MySQL database.\n     * This method may be overridden by child classes to create a DBMS-specific query builder.\n     * @return QueryBuilder query builder instance\n     */\n    public function createQueryBuilder()\n    {\n        return Yii::createObject(QueryBuilder::className(), [$this->db]);\n    }\n\n    /**\n     * {@inheritdoc}\n     * @return ColumnSchemaBuilder column schema builder instance\n     */\n    public function createColumnSchemaBuilder($type, $length = null)\n    {","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/sqlite/Schema.php#L187-L223","documentation":"yii\\db\\sqlite\\Schema::loadTableDefaultValues() throws NotSupportedException because SQLite has no named default-value constraints to introspect - defaults live per-column inside the CREATE TABLE DDL. The base Schema::getTableDefaultValues() API therefore cannot be honored on SQLite and fails fast with 'SQLite does not support default value constraints.'","triggerScenarios":"Calling Yii::$app->db->schema->getTableDefaultValues('order') (directly or through generic schema-inspection code) on a connection whose driverName is 'sqlite'; e.g. migration-diff tools or schema exporters that enumerate every schema facet.","commonSituations":"Generic schema-inspection/reporting code written against MySQL reused on SQLite; DB-diff or documentation generators that walk all getTable* methods; test harnesses asserting on full schema shape.","solutions":["Check the driver before introspecting: only call getTableDefaultValues() when Yii::$app->db->driverName !== 'sqlite'.","Read defaults from the column metadata instead: $schema->getTableSchema($table)->columns[$name]->defaultValue works on SQLite.","Restrict schema-diff tooling to columns/indexes/fkeys, which SQLite does expose.","If full parity matters, point the tooling at the production engine rather than a SQLite copy."],"exampleFix":"// before\n$defaults = Yii::$app->db->schema->getTableDefaultValues('order');\n\n// after\n$defaults = [];\nif (Yii::$app->db->driverName !== 'sqlite') {\n    $defaults = Yii::$app->db->schema->getTableDefaultValues('order');\n} else {\n    foreach (Yii::$app->db->schema->getTableSchema('order')->columns as $name => $column) {\n        if ($column->defaultValue !== null) {\n            $defaults[$name] = $column->defaultValue;\n        }\n    }\n}","handlingStrategy":"validation","validationCode":"if (Yii::$app->db->getDriverName() !== 'sqlite') {\n    $defaults = Yii::$app->db->schema->getTableDefaultValues('order');\n} else {\n    // per-column defaults are available from the table schema on SQLite\n    $columns = Yii::$app->db->schema->getTableSchema('order', true)->columns;\n}","typeGuard":null,"tryCatchPattern":"try {\n    $defaults = Yii::$app->db->schema->getTableDefaultValues('order');\n} catch (\\yii\\base\\NotSupportedException $e) {\n    $defaults = []; // SQLite: derive from getTableSchema()->columns instead\n}","preventionTips":["Build schema-inspection code against getTableSchema()->columns (portable) instead of named-constraint APIs.","Capability-check the driver before enumerating exotic schema facets.","Write one integration test per supported engine for schema tooling."],"tags":["sqlite","yii2","schema","introspection","default-value","not-supported"],"backgroundTag":"database-feature-unsupported","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}