{"record":{"id":"11310d6a24aa53e9","repo":"phalcon/cphalcon","slug":"identity-column-identityfield-isn-t-part-of-th","errorCode":null,"errorMessage":"Identity column '{identityField}' isn't part of the column map in '{className}'","messagePattern":"Identity column '(.+?)' isn't part of the column map in '(.+?)'","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Exceptions\\IdentityNotInColumnMap","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model.zep","lineNumber":4239,"sourceCode":"        if identityField !== false {\n            let defaultValue = connection->getDefaultIdValue();\n\n            /**\n             * Not all the database systems require an explicit value for\n             * identity columns\n             */\n            let useExplicitIdentity = (bool) connection->useExplicitIdValue();\n\n            if useExplicitIdentity {\n                let fields[] = identityField;\n            }\n\n            /**\n             * Check if the model has a column map\n             */\n            if typeof columnMap == \"array\" {\n                if unlikely !fetch attributeField, columnMap[identityField] {\n                    throw new IdentityNotInColumnMap(identityField, get_class(this));\n                }\n            } else {\n                let attributeField = identityField;\n            }\n\n            /**\n             * Check if the developer set an explicit value for the column\n             */\n            if fetch value, this->{attributeField} {\n                if value === null || value === \"\" {\n                    if useExplicitIdentity {\n                        let values[] = defaultValue, bindTypes[] = bindSkip;\n                    } elseif empty values {\n                        /**\n                         * Model has only the identity column; force an\n                         * explicit default so the underlying adapter does not\n                         * reject the insert because of an empty values array.\n                         */","sourceCodeStart":4221,"sourceCodeEnd":4257,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model.zep#L4221-L4257","documentation":"Thrown by Model::doLowInsert() (phalcon/Mvc/Model.zep:4239) when the model has an identity (auto-increment/sequence) column and that column is absent from the model's column map. The exception class is Phalcon\\Mvc\\Model\\Exceptions\\IdentityNotInColumnMap. It fires even before any value check, so any insert on such a model fails immediately.","triggerScenarios":"A model with a columnMap() that maps all data columns but forgets the primary key / identity column, followed by save()/create(). Also when the identity field name changed in the table (e.g. 'id' -> 'invoice_id') but the column map still uses the old key.","commonSituations":"Copy-pasting a columnMap() from another model and dropping the PK entry; renaming the PK column in a migration without updating columnMap(); composite or unusual PK names that the developer assumed were implicit.","solutions":["Add the identity column as a key in columnMap(), e.g. return ['the_id' => 'id', ...]","If the PK was renamed in the table, update both the columnMap() key and any model code referencing the property","Clear metadata cache to make sure the identity field name reported by metadata matches the columnMap key"],"exampleFix":"// before\npublic function columnMap()\n{\n    return ['name' => 'name', 'total' => 'total']; // 'invoice_id' identity omitted\n}\n// (new Invoice())->save(); // IdentityNotInColumnMap\n\n// after\npublic function columnMap()\n{\n    return [\n        'invoice_id' => 'id',\n        'name'      => 'name',\n        'total'     => 'total',\n    ];\n}","handlingStrategy":"validation","validationCode":"$metaData = $model->getModelsMetaData();\n$map = $metaData->getColumnMap($model);\n$identity = $metaData->getIdentityField($model);\nif (is_array($map) && $identity && !isset($map[$identity])) {\n    // identity column missing from columnMap(): fix the map before save()\n    throw new RuntimeException(\"columnMap lacks identity '{$identity}'\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Start every hand-written columnMap() from the PK entry","Cover the identity field in the model's consistency test","After PK renames, grep the codebase for old column names used as map keys"],"tags":["phalcon","orm","insert","identity","column-map","primary-key"],"backgroundTag":"orm-column-mapping-mismatch","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}