yiisoft/yii2 · error · NotSupportedException
__METHOD__ is not supported by SQLite.
Error message
__METHOD__ is not supported by SQLite.
What it means
yii\db\sqlite\QueryBuilder::dropUnique() always throws NotSupportedException (the raw message is built from __METHOD__, so it renders as 'yii\db\sqlite\QueryBuilder::dropUnique is not supported by SQLite.'). SQLite has no ALTER TABLE form to drop a named UNIQUE constraint; it can only drop a unique index created as an index.
Source
Thrown at framework/db/sqlite/QueryBuilder.php:382
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}
/**
* {@inheritdoc}
* @throws NotSupportedException this is not supported by SQLite.
*/
public function addUnique($name, $table, $columns)
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}
/**
* {@inheritdoc}
* @throws NotSupportedException this is not supported by SQLite.
*/
public function dropUnique($name, $table)
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}
/**
* {@inheritdoc}
* @throws NotSupportedException this is not supported by SQLite.
*/
public function addCheck($name, $table, $expression)
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}
/**
* {@inheritdoc}
* @throws NotSupportedException this is not supported by SQLite.
*/
public function dropCheck($name, $table)
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');View on GitHub (pinned to 66f00d18a2)
Solutions
- If the constraint was created as a unique index, drop the index instead: $this->dropIndex('uq_name', 'tbl').
- Otherwise rebuild the table without the UNIQUE clause (or with it, per the new schema) and copy data.
- Branch on $this->db->driverName === 'sqlite' and skip.
- Catch NotSupportedException in generic migration runners.
Example fix
// before
$this->dropUnique('uq_user_email', 'user');
// after
if ($this->db->driverName !== 'sqlite') {
$this->dropUnique('uq_user_email', 'user');
} else {
$this->dropIndex('uq_user_email', 'user'); // if created as a UNIQUE index
} Defensive patterns
Strategy: try-catch
Validate before calling
if ($db->driverName !== 'sqlite') {
$db->createCommand()->dropUnique($name, $table)->execute();
} else {
// If created as a unique index on sqlite, drop the index instead
$db->createCommand()->dropIndex($name, $table)->execute();
} Try / catch
try {
$db->createCommand()->dropUnique($name, $table)->execute();
} catch (\yii\db\NotSupportedException $e) {
// SQLite: try dropping the equivalent unique index; else rebuild the table
$db->createCommand()->dropIndex($name, $table)->execute();
} Prevention
- Track how each unique constraint was created (constraint vs index) per driver.
- Branch uniqueness removal on driver name.
- Keep a recreate-and-copy helper available for constraints that cannot be dropped on sqlite.
When it happens
Trigger: Executing $this->dropUnique('uq_name', 'tbl') in a migration rollback or schema cleanup on a sqlite connection.
Common situations: down() paths of migrations that added unique constraints, run on sqlite test databases; dropping uniqueness requirements via migration in cross-driver projects.
Related errors
- yii\db\sqlite\QueryBuilder::addUnique is not supported by SQ
- 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
- yii\db\sqlite\QueryBuilder::dropPrimaryKey is not supported
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/f52c78ab7a5f2eed.
Report an issue: GitHub.