yiisoft/yii2 · error · NotSupportedException
MySQL does not support default value constraints.
Error message
MySQL does not support default value constraints.
What it means
The Schema constraint API defines loadTableDefaultValues() for drivers with named DEFAULT constraints; MySQL stores defaults inline in column DDL, so there is nothing to introspect and the method unconditionally throws NotSupportedException. It exists only to satisfy the base-class contract.
Source
Thrown at framework/db/mysql/Schema.php:257
$check = new CheckConstraint(
[
'name' => $tableRow['constraint_name'],
'expression' => $tableRow['check_clause'],
]
);
$checks[] = $check;
}
return $checks;
}
/**
* {@inheritdoc}
* @throws NotSupportedException if this method is called.
*/
protected function loadTableDefaultValues($tableName)
{
throw new NotSupportedException('MySQL does not support default value constraints.');
}
/**
* Creates a query builder for the MySQL database.
* @return QueryBuilder query builder instance
*/
public function createQueryBuilder()
{
return Yii::createObject(QueryBuilder::className(), [$this->db]);
}
/**
* Resolves the table name and schema name (if any).
* @param TableSchema $table the table metadata object
* @param string $name the table name
*/
protected function resolveTableNames($table, $name)
{View on GitHub (pinned to 66f00d18a2)
Solutions
- Do not call getTableDefaultValues() on MySQL - the information does not exist.
- Read column defaults from the table schema instead: getTableSchema($t)->columns[$name]->defaultValue.
- In generic constraint loops, wrap the call in try/catch (NotSupportedException) or branch on driver name.
Example fix
// before
$defaults = $db->getTableDefaultValues('post');
// after
$defaults = array_map(
fn($c) => $c->defaultValue,
$db->getTableSchema('post', true)->columns
); Defensive patterns
Strategy: try-catch
Validate before calling
if ($db->driverName === 'mysql') {
// default-value constraints do not exist; read column defaults instead
$defaults = array_map(fn($c) => $c->defaultValue, $db->getTableSchema($t, true)->columns);
} else {
$defaults = $db->getTableDefaultValues($t);
} Try / catch
try {
$defaults = $db->getTableDefaultValues($table);
} catch (\yii\db\NotSupportedException $e) {
$defaults = []; // driver has no named DEFAULT constraints
} Prevention
- In generic constraint walkers, treat NotSupportedException as 'feature absent', not as a failure.
- Prefer column-schema defaults for MySQL; they are always available.
- Encode driver capability matrices in schema tooling instead of probing with live calls.
When it happens
Trigger: Calling $db->getTableDefaultValues('tbl') on a MySQL connection, usually from generic code that walks every constraint accessor (getTablePrimaryKey, getTableForeignKeys, getTableChecks, getTableDefaultValues) against an arbitrary connection.
Common situations: Cross-database tooling written against pgsql/mssql (where default-value constraints exist) reused on MySQL; ORM/admin-panel generators probing all constraint kinds.
Related errors
- Oracle does not support default value constraints.
- PostgreSQL does not support default value constraints.
- Table not found: $tableName
- There is no sequence associated with table '$tableName'.
- Unable to find column '$column' in table '$table'.
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/3b24d4ceb0aa2cee.
Report an issue: GitHub.