yiisoft/yii2 · error · yii\base\NotSupportedException

yii\db\cubrid\QueryBuilder::addCheck is not supported by CUB

Error message

yii\db\cubrid\QueryBuilder::addCheck is not supported by CUBRID.

What it means

yii\db\cubrid\QueryBuilder::addCheck() (framework/db/cubrid/QueryBuilder.php:204) throws NotSupportedException unconditionally — the CUBRID query builder provides no implementation for adding CHECK constraints. Any call path reaching it (yii\db\Command::addCheck(), or $this->addCheck() inside a migration) fails by design, reporting that the operation is unavailable on this DBMS driver.

Source

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

    {
        /** @var Schema $schema */
        $schema = $this->db->getSchema();
        foreach ($schema->getTableUniques($table) as $unique) {
            if ($unique->name === $name) {
                return $this->dropUnique($name, $table);
            }
        }

        return 'DROP INDEX ' . $this->db->quoteTableName($name) . ' ON ' . $this->db->quoteTableName($table);
    }

    /**
     * {@inheritdoc}
     * @throws NotSupportedException this is not supported by CUBRID.
     */
    public function addCheck($name, $table, $expression)
    {
        throw new NotSupportedException(__METHOD__ . ' is not supported by CUBRID.');
    }

    /**
     * {@inheritdoc}
     * @throws NotSupportedException this is not supported by CUBRID.
     */
    public function dropCheck($name, $table)
    {
        throw new NotSupportedException(__METHOD__ . ' is not supported by CUBRID.');
    }

    /**
     * {@inheritdoc}
     * @since 2.0.8
     */
    public function addCommentOnColumn($table, $column, $comment)
    {
        $definition = $this->getColumnDefinition($table, $column);

View on GitHub (pinned to 66f00d18a2)

Solutions

  1. Guard the migration by driver: if ($this->db->driverName !== 'cubrid') { $this->addCheck(...); }
  2. Catch yii\db\NotSupportedException around the call and log/skip when check constraints are optional
  3. If the constraint is mandatory on CUBRID, enforce it in model validation or raw SQL appropriate to your CUBRID version

Example fix

// before
$this->addCheck('chk_price', 'product', 'price >= 0'); // throws NotSupportedException on CUBRID

// after
if ($this->db->driverName !== 'cubrid') {
    $this->addCheck('chk_price', 'product', 'price >= 0');
}
Defensive patterns

Strategy: try-catch

Validate before calling

if ($this->db->driverName !== 'cubrid') {
    $this->addCheck('chk_price', 'product', 'price >= 0');
}

Try / catch

try {
    $this->addCheck('chk_price', 'product', 'price >= 0');
} catch (\yii\db\NotSupportedException $e) {
    // driver cannot add CHECK constraints — skip or enforce in model rules
    \Yii::info($e->getMessage(), __METHOD__);
}

Prevention

When it happens

Trigger: A migration written against MySQL/PostgreSQL calls $this->addCheck('chk_price','product','price >= 0') while the component's connection is CUBRID; shared migration templates that always add check constraints.

Common situations: Multi-database applications reusing one migration set across drivers; CI matrices running the same migrations on several DBMSs; Yii's CUBRID driver is community-maintained and implements fewer schema operations than mysql/pgsql.

Related errors


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