{"record":{"id":"ade29a46c5c112d5","repo":"yiisoft/yii2","slug":"there-is-no-sequence-associated-with-table-table-ade29a","errorCode":null,"errorMessage":"There is no sequence associated with table: $table","messagePattern":"There is no sequence associated with table: \\$table","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/db/oci/QueryBuilder.php","lineNumber":148,"sourceCode":"     * @param string $table the table whose index is to be dropped. The name will be properly quoted by the method.\n     * @return string the SQL statement for dropping an index.\n     */\n    public function dropIndex($name, $table)\n    {\n        return 'DROP INDEX ' . $this->db->quoteTableName($name);\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function executeResetSequence($table, $value = null)\n    {\n        $tableSchema = $this->db->getTableSchema($table);\n        if ($tableSchema === null) {\n            throw new InvalidArgumentException(\"Unknown table: $table\");\n        }\n        if ($tableSchema->sequenceName === null) {\n            throw new InvalidArgumentException(\"There is no sequence associated with table: $table\");\n        }\n\n        if ($value !== null) {\n            $value = (int) $value;\n        } else {\n            if (count($tableSchema->primaryKey) > 1) {\n                throw new InvalidArgumentException(\"Can't reset sequence for composite primary key in table: $table\");\n            }\n            // use master connection to get the biggest PK value\n            $value = $this->db->useMaster(function (Connection $db) use ($tableSchema) {\n                return $db->createCommand(\n                    'SELECT MAX(\"' . $tableSchema->primaryKey[0] . '\") FROM \"' . $tableSchema->name . '\"'\n                )->queryScalar();\n            }) + 1;\n        }\n\n        //Oracle needs at least two queries to reset sequence (see adding transactions and/or use alter method to avoid grants' issue?)\n        $this->db->createCommand('DROP SEQUENCE \"' . $tableSchema->sequenceName . '\"')->execute();","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/oci/QueryBuilder.php#L130-L166","documentation":"The Oracle executeResetSequence() drops and recreates TableSchema::sequenceName, so the table schema must expose a backing sequence. This exception fires when the schema was found but ->sequenceName is null: the primary key is not populated by an Oracle sequence (no IDENTITY column, no sequence+trigger pair).","triggerScenarios":"Calling $db->createCommand()->executeResetSequence('tbl') on a table whose PK is assigned by the application (UUIDs, natural keys) or populated by a trigger Yii cannot associate with a sequence during introspection.","commonSituations":"Legacy Oracle schemas with manually numbered PKs; tables using triggers Yii's introspection does not recognize as sequence-backed; fixture code ported from MySQL that resets every table.","solutions":["Check $schema->sequenceName !== null before calling executeResetSequence().","If auto-numbering is intended, convert the PK to an IDENTITY column or a documented sequence+trigger setup.","Skip the reset for tables with application-assigned keys - there is no sequence to reset.","Pass an explicit $value only when a sequence actually exists."],"exampleFix":"// before\n$db->createCommand()->executeResetSequence('audit_log');\n\n// after\n$schema = $db->getTableSchema('audit_log', true);\nif ($schema !== null && $schema->sequenceName !== null) {\n    $db->createCommand()->executeResetSequence('audit_log');\n}","handlingStrategy":"validation","validationCode":"$schema = $db->getTableSchema($table, true);\nif ($schema === null || $schema->sequenceName === null) {\n    return; // no sequence-backed PK: nothing to reset\n}\n$db->createCommand()->executeResetSequence($table)->execute();","typeGuard":null,"tryCatchPattern":"try {\n    $db->createCommand()->executeResetSequence($table)->execute();\n} catch (\\yii\\base\\InvalidArgumentException $e) {\n    if (str_contains($e->getMessage(), 'no sequence')) {\n        // PK not sequence-backed; skip\n    }\n}","preventionTips":["Verify IDENTITY/sequence+trigger setup when porting tables to Oracle.","Only reset sequences for tables introspected as sequence-backed.","Keep a driver-aware fixture helper rather than raw reset calls."],"tags":["yii2","php","oracle","oci","database","sequence","primary-key"],"backgroundTag":"missing-database-sequence","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}