yiisoft/yii2 · error · yii\base\InvalidArgumentException
There is no sequence associated with table '$tableName'.
Error message
There is no sequence associated with table '$tableName'.
What it means
MySQL has no standalone sequence objects; yii\db\mysql\QueryBuilder::resetSequence() maps sequences onto AUTO_INCREMENT columns via TableSchema::sequenceName. This exception fires when the table schema WAS found but ->sequenceName is null, i.e. the table has no AUTO_INCREMENT column, so there is nothing to reset.
Source
Thrown at framework/db/mysql/QueryBuilder.php:180
*/
public function resetSequence($tableName, $value = null)
{
$table = $this->db->getTableSchema($tableName);
if ($table !== null && $table->sequenceName !== null) {
$tableName = $this->db->quoteTableName($tableName);
if ($value === null) {
$key = reset($table->primaryKey);
$value = $this->db->createCommand("SELECT MAX(`$key`) FROM $tableName")->queryScalar() + 1;
} else {
$value = (int) $value;
}
return "ALTER TABLE $tableName AUTO_INCREMENT=$value";
} elseif ($table === null) {
throw new InvalidArgumentException("Table not found: $tableName");
}
throw new InvalidArgumentException("There is no 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. Meaningless for MySQL.
* @param string $table the table name. Meaningless for MySQL.
* @return string the SQL statement for checking integrity
*/
public function checkIntegrity($check = true, $schema = '', $table = '')
{
return 'SET FOREIGN_KEY_CHECKS = ' . ($check ? 1 : 0);
}
/**
* {@inheritdoc}
*/
public function buildLimit($limit, $offset)View on GitHub (pinned to 66f00d18a2)
Solutions
- Only call resetSequence() on tables whose primary key is an AUTO_INCREMENT column.
- If IDs are assigned by the application, remove the resetSequence() call - there is no counter to reset.
- If auto numbering is intended, alter the table so the PK column is AUTO_INCREMENT.
- Guard the call: check $db->getTableSchema($t)->sequenceName !== null first.
Example fix
// before
$db->createCommand()->resetSequence('order')->execute(); // 'order' uses UUID PKs
// after
$schema = $db->getTableSchema('order', true);
if ($schema !== null && $schema->sequenceName !== null) {
$db->createCommand()->resetSequence('order')->execute();
} Defensive patterns
Strategy: validation
Validate before calling
$schema = $db->getTableSchema($table, true);
if ($schema === null || $schema->sequenceName === null) {
// no AUTO_INCREMENT column: nothing to reset
return;
}
$db->createCommand()->resetSequence($table)->execute(); Try / catch
try {
$db->createCommand()->resetSequence($table)->execute();
} catch (\yii\base\InvalidArgumentException $e) {
if (str_contains($e->getMessage(), 'no sequence')) {
// table has no AUTO_INCREMENT column; safe to skip
}
} Prevention
- Maintain a whitelist of auto-increment tables for fixture resets instead of iterating all tables.
- Document which entities use UUID/application-assigned keys so reset logic can skip them.
- Assert sequenceName in test setup rather than during the reset call.
When it happens
Trigger: Calling resetSequence() on a table whose primary key is not AUTO_INCREMENT: a CHAR(36)/BINARY(16) UUID key, an app-assigned integer key, a composite key, or a table with no primary key at all.
Common situations: Fixture/base classes that blindly reset every table's sequence in projects using UUID or manually assigned primary keys; switching a table's PK strategy from auto-increment to application-generated IDs without updating fixture code.
Related errors
- Table not found: $tableName
- There is no sequence associated with table: $table
- Unable to find column '$column' in table '$table'.
- MySQL < 8.0.16 does not support check constraints.
- MySQL does not support default value constraints.
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/a555d850d5cfbc1a.
Report an issue: GitHub.