{"record":{"id":"86096b1d8edcb608","repo":"yiisoft/yii2","slug":"unable-to-find-column-column-in-table-table","errorCode":null,"errorMessage":"Unable to find column '$column' in table '$table'.","messagePattern":"Unable to find column '\\$column' in table '\\$table'\\.","errorType":"exception","errorClass":"yii\\db\\Exception","httpStatus":null,"severity":"error","filePath":"framework/db/cubrid/QueryBuilder.php","lineNumber":273,"sourceCode":"    {\n        return $this->addCommentOnTable($table, '');\n    }\n\n\n    /**\n     * Gets column definition.\n     *\n     * @param string $table table name\n     * @param string $column column name\n     * @return string|null the column definition\n     * @throws Exception in case when table does not contain column\n     * @since 2.0.8\n     */\n    private function getColumnDefinition($table, $column)\n    {\n        $row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->db->quoteTableName($table))->queryOne();\n        if ($row === false) {\n            throw new Exception(\"Unable to find column '$column' in table '$table'.\");\n        }\n        if (isset($row['Create Table'])) {\n            $sql = $row['Create Table'];\n        } else {\n            $row = array_values($row);\n            $sql = $row[1];\n        }\n        $sql = preg_replace('/^[^(]+\\((.*)\\).*$/', '\\1', $sql);\n        $sql = str_replace(', [', \",\\n[\", $sql);\n        if (preg_match_all('/^\\s*\\[(.*?)\\]\\s+(.*?),?$/m', $sql, $matches)) {\n            foreach ($matches[1] as $i => $c) {\n                if ($c === $column) {\n                    return $matches[2][$i];\n                }\n            }\n        }\n\n        return null;","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/cubrid/QueryBuilder.php#L255-L291","documentation":"yii\\db\\cubrid\\QueryBuilder::getColumnDefinition() (framework/db/cubrid/QueryBuilder.php:273) powers addCommentOnColumn()/dropCommentFromColumn() (framework/db/cubrid/QueryBuilder.php:220,247) by running SHOW CREATE TABLE and parsing column definitions. The 'Unable to find column' exception fires when that query returns false — meaning the table itself could not be read (usually it does not exist or is not visible to the connection), even though the message names the column. So despite the wording, this is a missing/unreadable table, not necessarily a missing column.","triggerScenarios":"$db->createCommand()->addCommentOnColumn('missing_table','name','comment')->execute(); a migration commenting columns before the table was created (ordering issue); wrong connection/database; a CUBRID user lacking permission to run SHOW CREATE TABLE.","commonSituations":"Migration ordering after refactors that create tables in later migrations; typos in table names; environment drift where the table exists in dev but not the target database.","solutions":["Verify the table first: if ($db->getTableSchema($table) === null) fail fast with an explicit message","Fix migration ordering so comment statements run after createTable/addColumn","Confirm the connection targets the right database and the user can execute SHOW CREATE TABLE"],"exampleFix":"// before\n$this->addCommentOnColumn('produt', 'sku', 'SKU'); // table name typo -> Exception\n\n// after\nif ($this->db->getTableSchema('product') === null) {\n    throw new \\yii\\console\\Exception('Table product does not exist; run base migrations first.');\n}\n$this->addCommentOnColumn('product', 'sku', 'SKU');","handlingStrategy":"validation","validationCode":"$schema = $db->getTableSchema($table);\nif ($schema === null) {\n    throw new \\InvalidArgumentException(\"Table '$table' not found — cannot comment columns.\");\n}\nif (!isset($schema->columns[$column])) {\n    throw new \\InvalidArgumentException(\"Column '$column' not found in '$table'.\");\n}\n$db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute();","typeGuard":null,"tryCatchPattern":"try {\n    $db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute();\n} catch (\\yii\\db\\Exception $e) {\n    \\Yii::error('addCommentOnColumn failed (table unreadable?): ' . $e->getMessage(), __METHOD__);\n}","preventionTips":["Validate both table and column against getTableSchema() before comment calls","Keep comment statements in the same migration that creates the table/column","Remember the message names the column but the check fails on an unreadable table"],"tags":["yii2","cubrid","database","schema","column-comment","migration"],"backgroundTag":"column-not-found","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}