{"record":{"id":"14a6c28433e5192b","repo":"phalcon/cphalcon","slug":"column-column-isn-t-part-of-the-table-columns","errorCode":null,"errorMessage":"Column '{column}' isn't part of the table columns in '{className}'","messagePattern":"Column '(.+?)' isn't part of the table columns in '(.+?)'","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Exceptions\\ColumnNotInTableColumns","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model.zep","lineNumber":4775,"sourceCode":"                let value = null;\n\n                if fetch value, this->{attributeField} {\n                    /**\n                     * We count how many fields are empty, if all fields are\n                     * empty we don't perform an 'exist' check\n                     */\n                    if value === null || value === \"\" {\n                        let numberEmpty++;\n                    }\n\n                    let uniqueParams[] = value;\n                } else {\n                    let uniqueParams[] = null,\n                        numberEmpty++;\n                }\n\n                if unlikely !fetch type, bindDataTypes[field] {\n                    throw new ColumnNotInTableColumns(field, get_class(this));\n                }\n\n                let uniqueTypes[] = type,\n                    wherePk[]     = connection->escapeIdentifier(field) . \" = ?\";\n            }\n\n            /**\n             * There are no primary key fields defined, assume the record does\n             * not exist\n             */\n            if numberPrimary == numberEmpty {\n                return false;\n            }\n\n            let joinWhere = join(\" AND \", wherePk);\n\n            /**\n             * The unique key is composed of 3 parts uniqueKey, uniqueParams,","sourceCodeStart":4757,"sourceCodeEnd":4793,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model.zep#L4757-L4793","documentation":"Thrown by Model::has() (phalcon/Mvc/Model.zep:4775): while collecting bind types for the primary-key WHERE condition, metaData->getBindTypes() has no entry for a PK field. The exception class is Phalcon\\Mvc\\Model\\Exceptions\\ColumnNotInTableColumns. The message says 'table columns' because bind types mirror the introspected column list.","triggerScenarios":"Any save() on a model whose bind-types metadata lacks a primary-key field: stale metadata cache after PK DDL, or a custom metadata provider whose bindTypes map omits the PK.","commonSituations":"PK column type changed (int to uuid) without a cache flush; manual metadata listing bind types for business columns only; metadata generated from a different table with the same name in another schema.","solutions":["Flush the model metadata cache after any PK-related DDL","Add the PK to the bindTypes map in the custom metadata provider (BIND_PARAM_INT for numeric, BIND_PARAM_STR for uuid/text)","Verify the model binds to the expected schema: getSchema()/getSource()"],"exampleFix":"// before\n$metaData = new MyMetaData($cache);\n// bindTypes: ['name' => Column::BIND_PARAM_STR] -- PK omitted\n$product->save(); // ColumnNotInTableColumns('product_id') in has()\n\n// after\n// 'bindTypes' => ['product_id' => Column::BIND_PARAM_INT, 'name' => Column::BIND_PARAM_STR, ...]\n$product->save();","handlingStrategy":"validation","validationCode":"$metaData = $model->getModelsMetaData();\n$bindTypes = $metaData->getBindTypes($model);\nforeach ($metaData->getPrimaryKeyAttributes($model) as $pk) {\n    if (!isset($bindTypes[$pk])) {\n        // existence check cannot bind the WHERE; reset metadata\n        $metaData->reset();\n        break;\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Flush metadata after PK type changes (int to uuid especially)","In custom providers, include PKs in the bindTypes map","Verify getSchema() in multi-schema environments so introspection reads the right table"],"tags":["phalcon","orm","save","primary-key","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"}