phalcon/cphalcon · error · ColumnTypeRequired

Column type is required

Error message

Column type is required

What it means

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.

Source

Thrown at phalcon/Db/Column.zep:595

    protected unsigned = false;

    /**
     * Phalcon\Db\Column constructor
     */
    public function __construct( string name,  array definition)
    {
        var type, notNull, primary, size, scale, dunsigned, first, after,
            bindType, isNumeric, autoIncrement, defaultValue, typeReference,
            typeValues, comment, generated, generationStored, invisible,
            isArray;

        let this->name = name;

        /**
         * Get the column type, one of the TYPE_* constants
         */
        if unlikely !fetch type, definition["type"] {
            throw new ColumnTypeRequired();
        }

        let this->type = type;

        if fetch typeReference, definition["typeReference"] {
            let this->typeReference = typeReference;
        }

        if fetch typeValues, definition["typeValues"] {
            let this->typeValues = typeValues;
        }

        /**
         * Check if the field is nullable
         */
        if fetch notNull, definition["notNull"] {
            let this->notNull = notNull;
        }

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Add 'type' => Column::TYPE_... to the definition.
  2. If the type arrives as a string from config, map it to the constant before constructing the Column.
  3. Assert array_key_exists('type', $definition) in your schema builder so failures surface with your own message.

Example fix

// before
$column = new Column('email', ['size' => 255, 'notNull' => true]); // throws ColumnTypeRequired

// after
use Phalcon\Db\Column;

$column = new Column('email', [
    'type'    => Column::TYPE_VARCHAR,
    'size'    => 255,
    'notNull' => true,
]);
Defensive patterns

Strategy: validation

Validate before calling

if (!isset($definition['type'])) {
    throw new InvalidArgumentException('Column definition requires a "type"');
}
$column = new Column('email', $definition);

Type guard

function columnDefinitionHasType(array $definition): bool
{
    return isset($definition['type']) && is_int($definition['type']);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/fc776e3abfed5658. Report an issue: GitHub.