{"record":{"id":"41537d9e5311663f","repo":"yiisoft/yii2","slug":"there-is-not-sequence-associated-with-table-tabl-41537d","errorCode":null,"errorMessage":"There is not sequence associated with table '$tableName'.","messagePattern":"There is not sequence associated with table '\\$tableName'\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/db/pgsql/QueryBuilder.php","lineNumber":199,"sourceCode":"    {\n        $table = $this->db->getTableSchema($tableName);\n        if ($table !== null && $table->sequenceName !== null) {\n            // c.f. https://www.postgresql.org/docs/8.1/functions-sequence.html\n            $sequence = $this->db->quoteTableName($table->sequenceName);\n            $tableName = $this->db->quoteTableName($tableName);\n            if ($value === null) {\n                $key = $this->db->quoteColumnName(reset($table->primaryKey));\n                $value = \"(SELECT COALESCE(MAX({$key}),0) FROM {$tableName})+1\";\n            } else {\n                $value = (int) $value;\n            }\n\n            return \"SELECT SETVAL('$sequence',$value,false)\";\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     * Builds a SQL statement for enabling or disabling integrity check.\n     * @param bool $check whether to turn on or off the integrity check.\n     * @param string $schema the schema of the tables.\n     * @param string $table the table name.\n     * @return string the SQL statement for checking integrity\n     */\n    public function checkIntegrity($check = true, $schema = '', $table = '')\n    {\n        /** @var Schema $dbSchema */\n        $dbSchema = $this->db->getSchema();\n        $enable = $check ? 'ENABLE' : 'DISABLE';\n        $schema = $schema ?: $dbSchema->defaultSchema;\n        $tableNames = $table ? [$table] : $dbSchema->getTableNames($schema);\n        $viewNames = $dbSchema->getViewNames($schema);\n        $tableNames = array_diff($tableNames, $viewNames);","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/pgsql/QueryBuilder.php#L181-L217","documentation":"PostgreSQL exposes sequences through serial/identity columns, surfaced as TableSchema::sequenceName. yii\\db\\pgsql\\QueryBuilder::resetSequence() throws this InvalidArgumentException when the table schema exists but ->sequenceName is null - the PK column is not serial/identity, so no sequence is attached. (The message contains a long-standing typo: 'There is not sequence'.)","triggerScenarios":"Calling resetSequence() on a table whose primary key is INTEGER without SERIAL/GENERATED BY DEFAULT AS IDENTITY, a UUID column defaulting to gen_random_uuid(), or any application-assigned key.","commonSituations":"Fixture code resetting all tables in projects using UUID PKs; tables migrated from other databases keeping plain integer keys; refactors from serial to UUID keys leaving stale reset calls.","solutions":["Guard the call: only reset when $schema->sequenceName !== null.","If auto-numbering is intended, convert the column to SERIAL/IDENTITY.","Remove the reset call for UUID or manually keyed tables - there is nothing to reseed.","Note the exact message wording when catching: it says 'is not sequence', not 'is no sequence'."],"exampleFix":"// before\n$db->createCommand()->resetSequence('session')->execute(); // UUID PK\n\n// after\n$schema = $db->getTableSchema('session', true);\nif ($schema !== null && $schema->sequenceName !== null) {\n    $db->createCommand()->resetSequence('session')->execute();\n}","handlingStrategy":"validation","validationCode":"$schema = $db->getTableSchema($table, true);\nif ($schema === null || $schema->sequenceName === null) {\n    return; // no serial/identity column: nothing to reset\n}\n$db->createCommand()->resetSequence($table)->execute();","typeGuard":null,"tryCatchPattern":"try {\n    $db->createCommand()->resetSequence($table)->execute();\n} catch (\\yii\\base\\InvalidArgumentException $e) {\n    // note the typo in the message: 'There is not sequence'\n    if (str_contains($e->getMessage(), 'not sequence')) {\n        // PK is not serial/identity; skip\n    }\n}","preventionTips":["Prefer IDENTITY columns for new PostgreSQL tables and record which tables are resettable.","Skip UUID-keyed tables in fixture reset loops.","Wrap reset logic in one helper that checks sequenceName once."],"tags":["yii2","php","postgresql","pgsql","database","sequence","serial","identity-column"],"backgroundTag":"missing-database-sequence","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}