yiisoft/yii2 · error · InvalidArgumentException
There is not sequence associated with table '$tableName'.
Error message
There is not sequence associated with table '$tableName'.
What it means
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'.)
Source
Thrown at framework/db/pgsql/QueryBuilder.php:199
{
$table = $this->db->getTableSchema($tableName);
if ($table !== null && $table->sequenceName !== null) {
// c.f. https://www.postgresql.org/docs/8.1/functions-sequence.html
$sequence = $this->db->quoteTableName($table->sequenceName);
$tableName = $this->db->quoteTableName($tableName);
if ($value === null) {
$key = $this->db->quoteColumnName(reset($table->primaryKey));
$value = "(SELECT COALESCE(MAX({$key}),0) FROM {$tableName})+1";
} else {
$value = (int) $value;
}
return "SELECT SETVAL('$sequence',$value,false)";
} elseif ($table === null) {
throw new InvalidArgumentException("Table not found: $tableName");
}
throw new InvalidArgumentException("There is not sequence associated with table '$tableName'.");
}
/**
* Builds a SQL statement for enabling or disabling integrity check.
* @param bool $check whether to turn on or off the integrity check.
* @param string $schema the schema of the tables.
* @param string $table the table name.
* @return string the SQL statement for checking integrity
*/
public function checkIntegrity($check = true, $schema = '', $table = '')
{
/** @var Schema $dbSchema */
$dbSchema = $this->db->getSchema();
$enable = $check ? 'ENABLE' : 'DISABLE';
$schema = $schema ?: $dbSchema->defaultSchema;
$tableNames = $table ? [$table] : $dbSchema->getTableNames($schema);
$viewNames = $dbSchema->getViewNames($schema);
$tableNames = array_diff($tableNames, $viewNames);View on GitHub (pinned to 66f00d18a2)
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'.
Example fix
// before
$db->createCommand()->resetSequence('session')->execute(); // UUID PK
// after
$schema = $db->getTableSchema('session', true);
if ($schema !== null && $schema->sequenceName !== null) {
$db->createCommand()->resetSequence('session')->execute();
} Defensive patterns
Strategy: validation
Validate before calling
$schema = $db->getTableSchema($table, true);
if ($schema === null || $schema->sequenceName === null) {
return; // no serial/identity column: nothing to reset
}
$db->createCommand()->resetSequence($table)->execute(); Try / catch
try {
$db->createCommand()->resetSequence($table)->execute();
} catch (\yii\base\InvalidArgumentException $e) {
// note the typo in the message: 'There is not sequence'
if (str_contains($e->getMessage(), 'not sequence')) {
// PK is not serial/identity; skip
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Table not found: $tableName
- PostgreSQL does not support default value constraints.
- Table not found: $tableName
- There is no sequence associated with table '$tableName'.
- Unknown table: $table
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/41537d9e5311663f.
Report an issue: GitHub.