{"record":{"id":"5993dda6055bce25","repo":"phalcon/cphalcon","slug":"generated-column-cannot-have-a-default-value","errorCode":null,"errorMessage":"Generated column cannot have a default value","messagePattern":"Generated column cannot have a default value","errorType":"exception","errorClass":"GeneratedDefaultConflict","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Column.zep","lineNumber":734,"sourceCode":"        }\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\"] {\n            let this->generationStored = (bool) generationStored;\n        }\n\n        /**\n         * Whether the column is INVISIBLE (MySQL 8.0.23+).\n         */\n        if fetch invisible, definition[\"invisible\"] {\n            let this->invisible = (bool) invisible;","sourceCodeStart":716,"sourceCodeEnd":752,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Column.zep#L716-L752","documentation":"Database-generated columns cannot also carry a DEFAULT value; the generation expression already determines the value. Phalcon\\Db\\Column therefore throws GeneratedDefaultConflict when a non-null 'generated' definition is combined with a non-null 'default'. It is the third consistency check in the constructor, after the type check and the auto-increment conflict.","triggerScenarios":"new Column('total', ['type' => Column::TYPE_DECIMAL, 'default' => 0, 'generated' => 'price * qty']); blueprint columns that ship a default and later gain a generation expression; definition mergers keeping the old 'default' key.","commonSituations":"Reusing a template column (with default) for a computed column; seed-style schemas where every column has a fallback default; migration tools merging old and new definitions instead of replacing.","solutions":["Remove 'default' from the generated column's definition.","If a fallback is needed, express it inside the generation expression (e.g. COALESCE(price * qty, 0)).","Strip 'default' and 'autoIncrement' keys programmatically when marking a column generated."],"exampleFix":"// before\n$column = new Column('total', [\n    'type'      => Column::TYPE_DECIMAL,\n    'size'      => 10,\n    'scale'     => 2,\n    'default'   => 0,\n    'generated' => 'price * qty', // throws GeneratedDefaultConflict\n]);\n\n// after\n$column = new Column('total', [\n    'type'      => Column::TYPE_DECIMAL,\n    'size'      => 10,\n    'scale'     => 2,\n    'generated' => 'COALESCE(price * qty, 0)',\n]);","handlingStrategy":"validation","validationCode":"if (isset($definition['generated']) && $definition['generated'] !== null\n    && array_key_exists('default', $definition)\n    && $definition['default'] !== null) {\n    unset($definition['default']); // or throw your own error\n}\n$column = new Column('total', $definition);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never ship 'default' on computed columns - put fallbacks in the expression (COALESCE).","Strip stale keys when converting an existing column to generated.","Unit-test schema builders for the generated/default/autoIncrement conflict rules."],"tags":["column","generated-column","default-value","conflict","phalcon-db"],"backgroundTag":"generated-column-conflict","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}