{"record":{"id":"fc776e3abfed5658","repo":"phalcon/cphalcon","slug":"column-type-is-required","errorCode":null,"errorMessage":"Column type is required","messagePattern":"Column type is required","errorType":"exception","errorClass":"ColumnTypeRequired","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Column.zep","lineNumber":595,"sourceCode":"    protected unsigned = false;\n\n    /**\n     * Phalcon\\Db\\Column constructor\n     */\n    public function __construct( string name,  array definition)\n    {\n        var type, notNull, primary, size, scale, dunsigned, first, after,\n            bindType, isNumeric, autoIncrement, defaultValue, typeReference,\n            typeValues, comment, generated, generationStored, invisible,\n            isArray;\n\n        let this->name = name;\n\n        /**\n         * Get the column type, one of the TYPE_* constants\n         */\n        if unlikely !fetch type, definition[\"type\"] {\n            throw new ColumnTypeRequired();\n        }\n\n        let this->type = type;\n\n        if fetch typeReference, definition[\"typeReference\"] {\n            let this->typeReference = typeReference;\n        }\n\n        if fetch typeValues, definition[\"typeValues\"] {\n            let this->typeValues = typeValues;\n        }\n\n        /**\n         * Check if the field is nullable\n         */\n        if fetch notNull, definition[\"notNull\"] {\n            let this->notNull = notNull;\n        }","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Column.zep#L577-L613","documentation":"Phalcon\\Db\\Column's constructor mandates definition['type'] - one of the Column::TYPE_* constants (TYPE_INTEGER, TYPE_VARCHAR, TYPE_DECIMAL, ...). Without a type the column cannot be mapped to SQL or to a PDO bind type, so the constructor throws ColumnTypeRequired immediately after assigning the name.","triggerScenarios":"new Column('name', ['size' => 10]) with no 'type'; column arrays built from config where the type entry was dropped; passing 'columnType' or 'datatype' instead of 'type'; describeColumns-based round trips where the key was renamed.","commonSituations":"Dynamic migrations built from YAML/JSON schema files; reusable column factories where the caller forgot the type; copy-paste between similarly named keys; schema DSLs that make type optional.","solutions":["Add 'type' => Column::TYPE_... to the definition.","If the type arrives as a string from config, map it to the constant before constructing the Column.","Assert array_key_exists('type', $definition) in your schema builder so failures surface with your own message."],"exampleFix":"// before\n$column = new Column('email', ['size' => 255, 'notNull' => true]); // throws ColumnTypeRequired\n\n// after\nuse Phalcon\\Db\\Column;\n\n$column = new Column('email', [\n    'type'    => Column::TYPE_VARCHAR,\n    'size'    => 255,\n    'notNull' => true,\n]);","handlingStrategy":"validation","validationCode":"if (!isset($definition['type'])) {\n    throw new InvalidArgumentException('Column definition requires a \"type\"');\n}\n$column = new Column('email', $definition);","typeGuard":"function columnDefinitionHasType(array $definition): bool\n{\n    return isset($definition['type']) && is_int($definition['type']);\n}","tryCatchPattern":null,"preventionTips":["Always write the 'type' entry first in any column definition.","Map string type names from config to Column::TYPE_* constants in one place.","Write a small ColumnFactory that refuses definitions without a type."],"tags":["column","schema-definition","phalcon-db"],"backgroundTag":"missing-required-array-key","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}