{"record":{"id":"6e501c179348f595","repo":"phalcon/cphalcon","slug":"identity-column-identityfield-isn-t-part-of-th-6e501c","errorCode":null,"errorMessage":"Identity column '{identityField}' isn't part of the table columns in '{className}'","messagePattern":"Identity column '(.+?)' isn't part of the table columns in '(.+?)'","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Exceptions\\IdentityNotInTableColumns","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model.zep","lineNumber":4275,"sourceCode":"                         */\n                        let fields[]    = identityField,\n                            values[]    = defaultValue,\n                            bindTypes[] = bindSkip;\n                    }\n                } else {\n                    /**\n                     * Add the explicit value to the field list if the user has\n                     * defined a value for it\n                     */\n                    if !useExplicitIdentity {\n                        let fields[] = identityField;\n                    }\n\n                    /**\n                     * The field is valid we look for a bind value (normally int)\n                     */\n                    if unlikely !fetch bindType, bindDataTypes[identityField] {\n                        throw new IdentityNotInTableColumns(identityField, get_class(this));\n                    }\n\n                    let values[]    = value,\n                        bindTypes[] = bindType;\n                }\n            } else {\n                if useExplicitIdentity {\n                    let values[]    = defaultValue,\n                        bindTypes[] = bindSkip;\n                } elseif empty values {\n                    /**\n                     * Model has only the identity column; force an explicit\n                     * default so the underlying adapter does not reject the\n                     * insert because of an empty values array.\n                     */\n                    let fields[]    = identityField,\n                        values[]    = defaultValue,\n                        bindTypes[] = bindSkip;","sourceCodeStart":4257,"sourceCodeEnd":4293,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model.zep#L4257-L4293","documentation":"Thrown by Model::doLowInsert() (phalcon/Mvc/Model.zep:4275) when the developer supplied an explicit non-empty value for the identity column and metaData->getBindTypes() has no bind type for it. The exception class is Phalcon\\Mvc\\Model\\Exceptions\\IdentityNotInTableColumns. It only triggers on the explicit-value branch, i.e. when you insert your own PK value.","triggerScenarios":"Setting $model->id = 123 (explicit PK) and saving, while bind-types metadata lacks the identity field. Common when metadata was cached before the PK column existed or was altered, or when a manual metadata provider omits the identity column from getBindTypes().","commonSituations":"Importing rows with fixed IDs into a table whose metadata cache is stale; custom metadata classes that list bind types only for non-PK columns; switching the identity column type (int -> uuid string) in the DB without refreshing metadata.","solutions":["Clear/flush the model metadata cache so bind types are re-introspected with the identity column","In a custom metadata provider, add the identity field to getBindTypes() (BIND_PARAM_INT for numeric PKs, BIND_PARAM_STR for UUIDs)","If the explicit value is unintended, remove the assignment and let the DB generate the identity value"],"exampleFix":"// before\n$invoice = new Invoice();\n$invoice->id = 1234; // explicit identity\n$invoice->save(); // IdentityNotInTableColumns\n\n// after\n// 1) flush metadata cache, or 2) fix provider:\n// 'bindTypes' => ['id' => Column::BIND_PARAM_INT, 'name' => Column::BIND_PARAM_STR, ...]\n$invoice->save();","handlingStrategy":"validation","validationCode":"$metaData = $model->getModelsMetaData();\n$identity = $metaData->getIdentityField($model);\n$bindTypes = $metaData->getBindTypes($model);\nif ($identity && !isset($bindTypes[$identity])) {\n    $metaData->reset(); // re-introspect before explicit-PK insert\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Flush metadata after changing PK type or name","Keep one source-of-truth array in custom metadata for attributes, dataTypes, bindTypes and primaryKeys","In integration tests, insert one row with an explicit PK value to exercise this path"],"tags":["phalcon","orm","insert","identity","bind-type","metadata"],"backgroundTag":"orm-metadata-schema-mismatch","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}