{"record":{"id":"055431307ac7aa5c","repo":"phalcon/cphalcon","slug":"column-generation-expression-must-be-a-string","errorCode":null,"errorMessage":"Column generation expression must be a string","messagePattern":"Column generation expression must be a string","errorType":"exception","errorClass":"InvalidGenerationExpression","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Column.zep","lineNumber":726,"sourceCode":"            let this->bindType = bindType;\n        }\n\n        /**\n         * Get the column comment\n         */\n         if fetch comment, definition[\"comment\"] {\n            let this->comment = comment;\n        }\n\n        /**\n         * Generated/computed column expression. When a non-empty string is\n         * provided the column is marked as generated and DEFAULT /\n         * AUTO_INCREMENT are no longer compatible at the dialect level.\n         */\n        if fetch generated, definition[\"generated\"] {\n            if generated !== null {\n                if unlikely typeof generated != \"string\" {\n                    throw new InvalidGenerationExpression();\n                }\n\n                if unlikely this->autoIncrement {\n                    throw new GeneratedAutoIncrementConflict();\n                }\n\n                if unlikely this->defaultValue !== null {\n                    throw new GeneratedDefaultConflict();\n                }\n\n                let this->generated = generated;\n            }\n        }\n\n        /**\n         * Storage flag for generated columns. true = STORED, false = VIRTUAL.\n         */\n        if fetch generationStored, definition[\"generationStored\"] {","sourceCodeStart":708,"sourceCodeEnd":744,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Column.zep#L708-L744","documentation":"Phalcon\\Db\\Column supports generated (computed) columns via definition['generated']. When the value is non-null it must be a string holding the SQL generation expression; any other PHP type (array, int, bool) throws InvalidGenerationExpression. null itself is allowed and simply means 'not generated'.","triggerScenarios":"new Column('full', ['type' => Column::TYPE_VARCHAR, 'generated' => ['first', 'last']]); passing an expression list instead of a pre-joined string; using true as a boolean marker for 'this column is generated'; numeric expression fragments from JSON.","commonSituations":"Config schemas expressing generated expressions as lists that were never implode()d; wrappers passing definition arrays verbatim from JSON; misunderstanding the key as a boolean flag rather than the expression text.","solutions":["Pass the SQL expression as a single string: 'generated' => \"CONCAT(first_name, ' ', last_name)\".","Join list-form expressions first: implode(', ', $parts).","Do not use 'generated' as a boolean marker - it carries the expression text itself."],"exampleFix":"// before\n$column = new Column('full_name', [\n    'type'      => Column::TYPE_VARCHAR,\n    'size'      => 255,\n    'generated' => ['first_name', 'last_name'], // throws InvalidGenerationExpression\n]);\n\n// after\n$column = new Column('full_name', [\n    'type'      => Column::TYPE_VARCHAR,\n    'size'      => 255,\n    'generated' => \"CONCAT(first_name, ' ', last_name)\",\n]);","handlingStrategy":"type-guard","validationCode":"if (isset($definition['generated'])\n    && $definition['generated'] !== null\n    && !is_string($definition['generated'])) {\n    throw new InvalidArgumentException('\"generated\" must be a SQL expression string');\n}\n$column = new Column('full_name', $definition);","typeGuard":"function generatedExpressionIsString(array $definition): bool\n{\n    return !isset($definition['generated'])\n        || $definition['generated'] === null\n        || is_string($definition['generated']);\n}","tryCatchPattern":null,"preventionTips":["Treat 'generated' as expression text, never a boolean or a list.","Implode array-shaped expressions at the config boundary.","Document the generated-column contract in your schema DSL."],"tags":["column","generated-column","type-validation","phalcon-db"],"backgroundTag":"invalid-parameter-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}