{"record":{"id":"f28dbc41c3ecf47b","repo":"yiisoft/yii2","slug":"table-not-found-tablename","errorCode":null,"errorMessage":"Table not found: $tableName","messagePattern":"Table not found: \\$tableName","errorType":"exception","errorClass":"yii\\base\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/db/cubrid/QueryBuilder.php","lineNumber":145,"sourceCode":"     * the next new row's primary key will have a value 1.\n     * @return string the SQL statement for resetting sequence\n     * @throws InvalidArgumentException if the table does not exist or there is no sequence associated with the table.\n     */\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;","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/cubrid/QueryBuilder.php#L127-L163","documentation":"yii\\db\\cubrid\\QueryBuilder::resetSequence() (framework/db/cubrid/QueryBuilder.php:131-148) resets a table's AUTO_INCREMENT counter and starts by resolving the table via $this->db->getTableSchema($tableName). When the lookup returns null the table does not exist from the schema's perspective and InvalidArgumentException 'Table not found' is thrown. It is reached through yii\\db\\Command::resetSequence() (framework/db/Command.php:971), typically called after truncating tables or loading fixtures to restart auto-increment.","triggerScenarios":"$db->createCommand()->resetSequence('user_typo')->execute(); calling resetSequence in fixture/migration code before the table was created; table-name case/spelling mismatch; stale schema cache holding pre-create metadata.","commonSituations":"Test fixtures resetting auto-increment after truncateTable(); CI runs against a database where migrations have not been applied; schema cache not invalidated after DDL executed outside the application.","solutions":["Verify the name first: if ($db->getTableSchema($tableName) === null) fail fast with a clear message or skip","Ensure migrations/DDL ran before resetSequence (fixture load order)","Refresh metadata when the cache is stale: $db->schema->refresh(), or clear the application cache component"],"exampleFix":"// before\n$db->createCommand()->resetSequence('order')->execute(); // throws if table missing\n\n// after\nif ($db->getTableSchema('order') !== null) {\n    $db->createCommand()->resetSequence('order')->execute();\n}","handlingStrategy":"validation","validationCode":"if ($db->getTableSchema($tableName) === null) {\n    throw new \\InvalidArgumentException(\"Cannot reset sequence: table '$tableName' does not exist.\");\n}\n$db->createCommand()->resetSequence($tableName)->execute();","typeGuard":null,"tryCatchPattern":"try {\n    $db->createCommand()->resetSequence($tableName)->execute();\n} catch (\\yii\\db\\Exception $e) {\n    \\Yii::warning('resetSequence failed: ' . $e->getMessage(), __METHOD__);\n}","preventionTips":["Resolve table names via getTableSchema() before any sequence/DDL helper call","Run migrations before fixture jobs that reset sequences","Call $db->schema->refresh() after out-of-band DDL to avoid stale metadata"],"tags":["yii2","cubrid","database","sequence","schema","fixture"],"backgroundTag":"table-not-found","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}