{"record":{"id":"26b46b1ac9f1d0d2","repo":"phalcon/cphalcon","slug":"column-type-cannot-be-auto-increment","errorCode":null,"errorMessage":"Column type cannot be auto-increment","messagePattern":"Column type cannot be auto-increment","errorType":"exception","errorClass":"ColumnTypeRejectsAutoIncrement","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Column.zep","lineNumber":685,"sourceCode":"\n        /**\n         * Check if the field is auto-increment/serial\n         */\n        if fetch autoIncrement, definition[\"autoIncrement\"] {\n            if !autoIncrement {\n                let this->autoIncrement = false;\n            } else {\n                switch type {\n                    case self::TYPE_BIGINTEGER:\n                    case self::TYPE_INTEGER:\n                    case self::TYPE_MEDIUMINTEGER:\n                    case self::TYPE_SMALLINTEGER:\n                    case self::TYPE_TINYINTEGER:\n                        let this->autoIncrement = true;\n                        break;\n\n                    default:\n                        throw new ColumnTypeRejectsAutoIncrement();\n                }\n            }\n        }\n\n        /**\n         * Check if the field is placed at the first position of the table\n         */\n        if fetch first, definition[\"first\"] {\n            let this->first = first;\n        }\n\n        /**\n         * Name of the column which is placed before the current field\n         */\n        if fetch after, definition[\"after\"] {\n            let this->after = after;\n        }\n","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Column.zep#L667-L703","documentation":"Phalcon\\Db\\Column allows 'autoIncrement' => true only for integer types: BIGINTEGER, INTEGER, MEDIUMINTEGER, SMALLINTEGER and TINYINTEGER. Requesting auto-increment on any other type (VARCHAR, DECIMAL, DATE, ...) throws ColumnTypeRejectsAutoIncrement before SQL generation - the database would reject it too.","triggerScenarios":"new Column('uuid', ['type' => Column::TYPE_VARCHAR, 'primary' => true, 'autoIncrement' => true]); copying an integer id blueprint onto a string key; autoIncrement on DECIMAL (which MySQL itself disallows).","commonSituations":"Switching primary keys from int to UUID/string without removing autoIncrement; generic BaseModel schemas marking every primary key auto-increment; migrations cloned from an integer-keyed table; ORM defaults leaking into custom columns.","solutions":["Remove 'autoIncrement' from non-integer key columns and generate the key in application code (e.g. UUIDs).","Keep an integer type if you want database-side auto-increment.","Emit 'autoIncrement' only when the type is in the integer TYPE_* set."],"exampleFix":"// before\n$column = new Column('uuid', [\n    'type'          => Column::TYPE_VARCHAR,\n    'size'          => 36,\n    'primary'       => true,\n    'autoIncrement' => true, // throws ColumnTypeRejectsAutoIncrement\n]);\n\n// after\n$column = new Column('uuid', [\n    'type'    => Column::TYPE_VARCHAR,\n    'size'    => 36,\n    'primary' => true,\n]); // generate UUIDs in application code","handlingStrategy":"type-guard","validationCode":"$aiTypes = [\n    Column::TYPE_BIGINTEGER, Column::TYPE_INTEGER, Column::TYPE_MEDIUMINTEGER,\n    Column::TYPE_SMALLINTEGER, Column::TYPE_TINYINTEGER,\n];\nif (!empty($definition['autoIncrement'])\n    && !in_array($definition['type'], $aiTypes, true)) {\n    unset($definition['autoIncrement']);\n}\n$column = new Column('uuid', $definition);","typeGuard":"function typeSupportsAutoIncrement(int $type): bool\n{\n    return in_array($type, [\n        Column::TYPE_BIGINTEGER, Column::TYPE_INTEGER, Column::TYPE_MEDIUMINTEGER,\n        Column::TYPE_SMALLINTEGER, Column::TYPE_TINYINTEGER,\n    ], true);\n}","tryCatchPattern":null,"preventionTips":["Non-integer primary keys mean application-side key generation - never autoIncrement.","Centralize id-column blueprints so the type/autoIncrement pair is always consistent.","When migrating int keys to UUIDs, grep schema code for autoIncrement first."],"tags":["column","auto-increment","primary-key","phalcon-db"],"backgroundTag":"auto-increment-on-non-integer-column","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}