{"record":{"id":"1254d550b2f95e74","repo":"yiisoft/yii2","slug":"oracle-does-not-support-on-update-clause","errorCode":null,"errorMessage":"Oracle does not support ON UPDATE clause.","messagePattern":"Oracle does not support ON UPDATE clause\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"framework/db/oci/QueryBuilder.php","lineNumber":185,"sourceCode":"        $this->db->createCommand('CREATE SEQUENCE \"' . $tableSchema->sequenceName . '\" START WITH ' . $value\n            . ' INCREMENT BY 1 NOMAXVALUE NOCACHE')->execute();\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)\n    {\n        $sql = 'ALTER TABLE ' . $this->db->quoteTableName($table)\n            . ' ADD CONSTRAINT ' . $this->db->quoteColumnName($name)\n            . ' FOREIGN KEY (' . $this->buildColumns($columns) . ')'\n            . ' REFERENCES ' . $this->db->quoteTableName($refTable)\n            . ' (' . $this->buildColumns($refColumns) . ')';\n        if ($delete !== null) {\n            $sql .= ' ON DELETE ' . $delete;\n        }\n        if ($update !== null) {\n            throw new Exception('Oracle does not support ON UPDATE clause.');\n        }\n\n        return $sql;\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    protected function prepareInsertValues($table, $columns, $params = [])\n    {\n        list($names, $placeholders, $values, $params) = parent::prepareInsertValues($table, $columns, $params);\n        if (!$columns instanceof Query && empty($names)) {\n            $tableSchema = $this->db->getSchema()->getTableSchema($table);\n            if ($tableSchema !== null) {\n                $columns = !empty($tableSchema->primaryKey) ? $tableSchema->primaryKey : [reset($tableSchema->columns)->name];\n                foreach ($columns as $name) {\n                    $names[] = $this->db->quoteColumnName($name);\n                    $placeholders[] = 'DEFAULT';","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/oci/QueryBuilder.php#L167-L203","documentation":"Oracle foreign keys support only the ON DELETE referential action; ON UPDATE does not exist in Oracle DDL. yii\\db\\oci\\QueryBuilder::addForeignKey() therefore builds the ALTER TABLE ... FOREIGN KEY ... ON DELETE clause and throws yii\\db\\Exception as soon as a non-null $update option is passed.","triggerScenarios":"A migration or schema call like $this->addForeignKey('fk', 't', ['ref_id'], 'ref', ['id'], 'CASCADE', 'CASCADE') - any non-null seventh argument ($update) on an Oracle connection.","commonSituations":"Migrations shared between MySQL/PostgreSQL (where ON UPDATE CASCADE is common) and Oracle; FK definitions copied from MySQL documentation; multi-driver applications with a single migration set.","solutions":["Omit the $update argument (pass null) for Oracle - ON DELETE alone is fine.","Branch per driver when defining FKs and only send $update where supported.","If ON UPDATE behavior is mandatory, implement it with a database trigger instead.","Catch yii\\db\\Exception in generic schema builders and retry without the update option."],"exampleFix":"// before\n$this->addForeignKey('fk_order_user', 'order', ['user_id'], 'user', ['id'], 'RESTRICT', 'CASCADE');\n\n// after\nif ($this->db->driverName === 'oci') {\n    $this->addForeignKey('fk_order_user', 'order', ['user_id'], 'user', ['id'], 'RESTRICT', null);\n} else {\n    $this->addForeignKey('fk_order_user', 'order', ['user_id'], 'user', ['id'], 'RESTRICT', 'CASCADE');\n}","handlingStrategy":"validation","validationCode":"// Driver-aware FK options: Oracle has no ON UPDATE\n$update = ($db->driverName === 'oci') ? null : 'CASCADE';\n$this->addForeignKey('fk_order_user', 'order', ['user_id'], 'user', ['id'], 'RESTRICT', $update);","typeGuard":null,"tryCatchPattern":"try {\n    $sql = $db->getQueryBuilder()->addForeignKey($name, $table, $cols, $refTable, $refCols, $delete, $update);\n} catch (\\yii\\db\\Exception $e) {\n    // Oracle: retry without the ON UPDATE option\n    $sql = $db->getQueryBuilder()->addForeignKey($name, $table, $cols, $refTable, $refCols, $delete, null);\n}","preventionTips":["Keep per-driver DDL option maps instead of hardcoding FK options.","Avoid ON UPDATE CASCADE in portable schemas; few drivers support it alike.","Add Oracle to the CI driver matrix when migrations must stay portable."],"tags":["yii2","php","oracle","oci","database","foreign-key","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"}