yiisoft/yii2 · error · yii\base\InvalidArgumentException

There is not sequence associated with table '$tableName'.

Error message

There is not sequence associated with table '$tableName'.

What it means

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.

Source

Thrown at framework/db/cubrid/QueryBuilder.php:148

     */
    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 = (int) $this->db->createCommand("SELECT MAX(`$key`) FROM " . $this->db->schema->quoteTableName($tableName))->queryScalar() + 1;
            } else {
                $value = (int) $value;
            }

            return 'ALTER TABLE ' . $this->db->schema->quoteTableName($tableName) . " AUTO_INCREMENT=$value;";
        } elseif ($table === null) {
            throw new InvalidArgumentException("Table not found: $tableName");
        }

        throw new InvalidArgumentException("There is not sequence associated with table '$tableName'.");
    }

    /**
     * {@inheritdoc}
     */
    public function buildLimit($limit, $offset)
    {
        $sql = '';
        // limit is not optional in CUBRID
        // https://www.cubrid.org/manual/en/9.3.0/sql/query/select.html#limit-clause
        // "You can specify a very big integer for row_count to display to the last row, starting from a specific row."
        if ($this->hasLimit($limit)) {
            $sql = 'LIMIT ' . $limit;
            if ($this->hasOffset($offset)) {
                $sql .= ' OFFSET ' . $offset;
            }
        } elseif ($this->hasOffset($offset)) {
            $sql = "LIMIT 9223372036854775807 OFFSET $offset"; // 2^63-1

View on GitHub (pinned to 66f00d18a2)

Solutions

  1. Skip resetSequence for tables without a sequence: check $db->getTableSchema($table)->sequenceName !== null first
  2. If the table should auto-increment, alter it so the PK column is AUTO_INCREMENT, then retry
  3. Restrict sequence resets to the tables that actually use auto-increment (usually fixture-driving tables)

Example fix

// before
foreach ($tables as $t) {
    $db->createCommand()->resetSequence($t)->execute(); // throws on sequence-less tables
}

// after
foreach ($tables as $t) {
    $schema = $db->getTableSchema($t);
    if ($schema !== null && $schema->sequenceName !== null) {
        $db->createCommand()->resetSequence($t)->execute();
    }
}
Defensive patterns

Strategy: validation

Validate before calling

$schema = $db->getTableSchema($table);
if ($schema !== null && $schema->sequenceName !== null) {
    $db->createCommand()->resetSequence($table)->execute();
} // else: table missing or has no AUTO_INCREMENT column — nothing to reseed

Try / catch

try {
    $db->createCommand()->resetSequence($table)->execute();
} catch (\yii\db\Exception $e) {
    \Yii::warning("Skipped sequence reset for '$table': " . $e->getMessage(), __METHOD__);
}

Prevention

When it happens

Trigger: $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.

Common situations: Fixture base classes looping over all tables; data porting where the auto-increment property was lost; assuming every primary key has a sequence.

Related errors


AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17). Data as JSON: /api/errors/ddbd969362f52102. Report an issue: GitHub.