{"record":{"id":"ddbd969362f52102","repo":"yiisoft/yii2","slug":"there-is-not-sequence-associated-with-table-tabl","errorCode":null,"errorMessage":"There is not sequence associated with table '$tableName'.","messagePattern":"There is not sequence associated with table '\\$tableName'\\.","errorType":"exception","errorClass":"yii\\base\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/db/cubrid/QueryBuilder.php","lineNumber":148,"sourceCode":"     */\n    public function resetSequence($tableName, $value = null)\n    {\n        $table = $this->db->getTableSchema($tableName);\n        if ($table !== null && $table->sequenceName !== null) {\n            $tableName = $this->db->quoteTableName($tableName);\n            if ($value === null) {\n                $key = reset($table->primaryKey);\n                $value = (int) $this->db->createCommand(\"SELECT MAX(`$key`) FROM \" . $this->db->schema->quoteTableName($tableName))->queryScalar() + 1;\n            } else {\n                $value = (int) $value;\n            }\n\n            return 'ALTER TABLE ' . $this->db->schema->quoteTableName($tableName) . \" AUTO_INCREMENT=$value;\";\n        } elseif ($table === null) {\n            throw new InvalidArgumentException(\"Table not found: $tableName\");\n        }\n\n        throw new InvalidArgumentException(\"There is not sequence associated with table '$tableName'.\");\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function buildLimit($limit, $offset)\n    {\n        $sql = '';\n        // limit is not optional in CUBRID\n        // https://www.cubrid.org/manual/en/9.3.0/sql/query/select.html#limit-clause\n        // \"You can specify a very big integer for row_count to display to the last row, starting from a specific row.\"\n        if ($this->hasLimit($limit)) {\n            $sql = 'LIMIT ' . $limit;\n            if ($this->hasOffset($offset)) {\n                $sql .= ' OFFSET ' . $offset;\n            }\n        } elseif ($this->hasOffset($offset)) {\n            $sql = \"LIMIT 9223372036854775807 OFFSET $offset\"; // 2^63-1","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/cubrid/QueryBuilder.php#L130-L166","documentation":"The second failure mode of yii\\db\\cubrid\\QueryBuilder::resetSequence() (framework/db/cubrid/QueryBuilder.php:148): the table exists (getTableSchema returned a TableSchema) but $table->sequenceName is null, i.e. the table has no AUTO_INCREMENT column backing its primary key. Since the method's only implementation emits 'ALTER TABLE ... AUTO_INCREMENT=', calling it on a table without an auto-increment column throws InvalidArgumentException.","triggerScenarios":"$db->createCommand()->resetSequence('audit_log')->execute() where audit_log's PK was created without AUTO_INCREMENT; generic fixture/teardown code that indiscriminately resets every table's sequence; tables imported without their auto-increment attribute.","commonSituations":"Fixture base classes looping over all tables; data porting where the auto-increment property was lost; assuming every primary key has a sequence.","solutions":["Skip resetSequence for tables without a sequence: check $db->getTableSchema($table)->sequenceName !== null first","If the table should auto-increment, alter it so the PK column is AUTO_INCREMENT, then retry","Restrict sequence resets to the tables that actually use auto-increment (usually fixture-driving tables)"],"exampleFix":"// before\nforeach ($tables as $t) {\n    $db->createCommand()->resetSequence($t)->execute(); // throws on sequence-less tables\n}\n\n// after\nforeach ($tables as $t) {\n    $schema = $db->getTableSchema($t);\n    if ($schema !== null && $schema->sequenceName !== null) {\n        $db->createCommand()->resetSequence($t)->execute();\n    }\n}","handlingStrategy":"validation","validationCode":"$schema = $db->getTableSchema($table);\nif ($schema !== null && $schema->sequenceName !== null) {\n    $db->createCommand()->resetSequence($table)->execute();\n} // else: table missing or has no AUTO_INCREMENT column — nothing to reseed","typeGuard":null,"tryCatchPattern":"try {\n    $db->createCommand()->resetSequence($table)->execute();\n} catch (\\yii\\db\\Exception $e) {\n    \\Yii::warning(\"Skipped sequence reset for '$table': \" . $e->getMessage(), __METHOD__);\n}","preventionTips":["Treat sequenceName as the capability flag for resetSequence on CUBRID/MSSQL","Maintain an explicit list of auto-increment tables in fixtures instead of iterating all tables","Verify imported schemas kept their AUTO_INCREMENT attribute"],"tags":["yii2","cubrid","database","sequence","schema","fixture"],"backgroundTag":"missing-database-sequence","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}