{"record":{"id":"7d6c2f93b57760fe","repo":"phalcon/cphalcon","slug":"generated-column-cannot-also-be-auto-increment","errorCode":null,"errorMessage":"Generated column cannot also be auto-increment","messagePattern":"Generated column cannot also be auto-increment","errorType":"exception","errorClass":"GeneratedAutoIncrementConflict","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Column.zep","lineNumber":730,"sourceCode":"         * 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\"] {\n            let this->generationStored = (bool) generationStored;\n        }\n\n        /**","sourceCodeStart":712,"sourceCodeEnd":748,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Column.zep#L712-L748","documentation":"A column cannot be both generated (computed by the database) and auto-increment - the two value-generation strategies are mutually exclusive. Phalcon\\Db\\Column enforces this in the constructor: after validating that 'generated' is a string, an 'autoIncrement' => true definition combined with a non-null 'generated' throws GeneratedAutoIncrementConflict.","triggerScenarios":"new Column('id', ['type' => Column::TYPE_INTEGER, 'autoIncrement' => true, 'generated' => '...']); copying a standard id blueprint and then adding a generation expression; attempting to make an identity column also computed.","commonSituations":"Extending default model schemas (which ship autoIncrement id columns) with generated columns; migration refactors converting a column to computed without stripping the old flag; definition mergers that union both keys.","solutions":["Remove 'autoIncrement' from the definition of the generated column.","Keep the numeric auto-increment id as a separate column from any computed column.","When marking a column generated, strip both 'autoIncrement' and 'default' programmatically."],"exampleFix":"// before\n$column = new Column('id', [\n    'type'          => Column::TYPE_INTEGER,\n    'primary'       => true,\n    'autoIncrement' => true,\n    'generated'     => 'some_expr', // throws GeneratedAutoIncrementConflict\n]);\n\n// after - computed column, no auto-increment\n$column = new Column('id', [\n    'type'      => Column::TYPE_INTEGER,\n    'primary'   => true,\n    'generated' => 'some_expr',\n]);","handlingStrategy":"validation","validationCode":"if (isset($definition['generated']) && $definition['generated'] !== null\n    && !empty($definition['autoIncrement'])) {\n    throw new InvalidArgumentException('A generated column cannot be auto-increment');\n}\n$column = new Column('id', $definition);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["One generation mechanism per column: auto-increment, default, or generated - never two.","Review id-column blueprints before adding computed expressions.","Validate definitions against a conflict matrix in your schema builder."],"tags":["column","generated-column","auto-increment","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"}