yiisoft/yii2 · error · NotSupportedException
SQLite does not support default value constraints.
Error message
SQLite does not support default value constraints.
What it means
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.'
Source
Thrown at framework/db/sqlite/Schema.php:205
if (isset($createTableToken[$firstMatchIndex - 2]) && $createTableToken->matches($pattern, $firstMatchIndex - 2)) {
$name = $createTableToken[$firstMatchIndex - 1]->content;
}
$result[] = new CheckConstraint([
'name' => $name,
'expression' => $checkSql,
]);
}
return $result;
}
/**
* {@inheritdoc}
* @throws NotSupportedException if this method is called.
*/
protected function loadTableDefaultValues($tableName)
{
throw new NotSupportedException('SQLite does not support default value constraints.');
}
/**
* Creates a query builder for the MySQL database.
* This method may be overridden by child classes to create a DBMS-specific query builder.
* @return QueryBuilder query builder instance
*/
public function createQueryBuilder()
{
return Yii::createObject(QueryBuilder::className(), [$this->db]);
}
/**
* {@inheritdoc}
* @return ColumnSchemaBuilder column schema builder instance
*/
public function createColumnSchemaBuilder($type, $length = null)
{View on GitHub (pinned to 66f00d18a2)
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.
Example fix
// before
$defaults = Yii::$app->db->schema->getTableDefaultValues('order');
// after
$defaults = [];
if (Yii::$app->db->driverName !== 'sqlite') {
$defaults = Yii::$app->db->schema->getTableDefaultValues('order');
} else {
foreach (Yii::$app->db->schema->getTableSchema('order')->columns as $name => $column) {
if ($column->defaultValue !== null) {
$defaults[$name] = $column->defaultValue;
}
}
} Defensive patterns
Strategy: validation
Validate before calling
if (Yii::$app->db->getDriverName() !== 'sqlite') {
$defaults = Yii::$app->db->schema->getTableDefaultValues('order');
} else {
// per-column defaults are available from the table schema on SQLite
$columns = Yii::$app->db->schema->getTableSchema('order', true)->columns;
} Try / catch
try {
$defaults = Yii::$app->db->schema->getTableDefaultValues('order');
} catch (\yii\base\NotSupportedException $e) {
$defaults = []; // SQLite: derive from getTableSchema()->columns instead
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- CUBRID does not support default value constraints.
- CUBRID does not support check constraints.
- yii\db\sqlite\QueryBuilder::dropForeignKey is not supported
- yii\db\sqlite\QueryBuilder::alterColumn is not supported by
- yii\db\sqlite\QueryBuilder::addPrimaryKey is not supported b
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/eb07d51e6b2cd2e6.
Report an issue: GitHub.