{"record":{"id":"f52c78ab7a5f2eed","repo":"yiisoft/yii2","slug":"method-is-not-supported-by-sqlite","errorCode":null,"errorMessage":"__METHOD__ is not supported by SQLite.","messagePattern":"__METHOD__ is not supported by SQLite\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"framework/db/sqlite/QueryBuilder.php","lineNumber":382,"sourceCode":"        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');\n    }\n\n    /**\n     * {@inheritdoc}\n     * @throws NotSupportedException this is not supported by SQLite.\n     */\n    public function addUnique($name, $table, $columns)\n    {\n        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');\n    }\n\n    /**\n     * {@inheritdoc}\n     * @throws NotSupportedException this is not supported by SQLite.\n     */\n    public function dropUnique($name, $table)\n    {\n        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');\n    }\n\n    /**\n     * {@inheritdoc}\n     * @throws NotSupportedException this is not supported by SQLite.\n     */\n    public function addCheck($name, $table, $expression)\n    {\n        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');\n    }\n\n    /**\n     * {@inheritdoc}\n     * @throws NotSupportedException this is not supported by SQLite.\n     */\n    public function dropCheck($name, $table)\n    {\n        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/sqlite/QueryBuilder.php#L364-L400","documentation":"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.","triggerScenarios":"Executing $this->dropUnique('uq_name', 'tbl') in a migration rollback or schema cleanup on a sqlite connection.","commonSituations":"down() paths of migrations that added unique constraints, run on sqlite test databases; dropping uniqueness requirements via migration in cross-driver projects.","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."],"exampleFix":"// before\n$this->dropUnique('uq_user_email', 'user');\n\n// after\nif ($this->db->driverName !== 'sqlite') {\n    $this->dropUnique('uq_user_email', 'user');\n} else {\n    $this->dropIndex('uq_user_email', 'user'); // if created as a UNIQUE index\n}","handlingStrategy":"try-catch","validationCode":"if ($db->driverName !== 'sqlite') {\n    $db->createCommand()->dropUnique($name, $table)->execute();\n} else {\n    // If created as a unique index on sqlite, drop the index instead\n    $db->createCommand()->dropIndex($name, $table)->execute();\n}","typeGuard":null,"tryCatchPattern":"try {\n    $db->createCommand()->dropUnique($name, $table)->execute();\n} catch (\\yii\\db\\NotSupportedException $e) {\n    // SQLite: try dropping the equivalent unique index; else rebuild the table\n    $db->createCommand()->dropIndex($name, $table)->execute();\n}","preventionTips":["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."],"tags":["yii2","php","sqlite","database","unique-constraint","migration","not-supported"],"backgroundTag":"unsupported-driver-operation","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}