phalcon/cphalcon · error · ColumnTypeRejectsScale

Column type does not support scale parameter

Error message

Column type does not support scale parameter

What it means

Phalcon\Db\Column only accepts a 'scale' (decimal digits) definition for numeric types: BIGINTEGER, DECIMAL, DOUBLE, FLOAT, INTEGER, MEDIUMINTEGER, SMALLINTEGER and TINYINTEGER. Combining any other type with 'scale' throws ColumnTypeRejectsScale, because e.g. a VARCHAR or DATE with a scale is meaningless SQL.

Source

Thrown at phalcon/Db/Column.zep:643

        /**
         * Check if the column has a decimal scale
         */
        if fetch scale, definition["scale"] {
            switch type {
                case self::TYPE_BIGINTEGER:
                case self::TYPE_DECIMAL:
                case self::TYPE_DOUBLE:
                case self::TYPE_FLOAT:
                case self::TYPE_INTEGER:
                case self::TYPE_MEDIUMINTEGER:
                case self::TYPE_SMALLINTEGER:
                case self::TYPE_TINYINTEGER:
                    let this->scale = scale;
                    break;

                default:
                    throw new ColumnTypeRejectsScale();
            }
        }

        /**
         * Check if the column is default value
         */
        if fetch defaultValue, definition["default"] {
            let this->defaultValue = defaultValue;
        }

        /**
         * Check if the field is unsigned (only MySQL)
         */
        if fetch dunsigned, definition["unsigned"] {
            let this->unsigned = dunsigned;
        }

        /**

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Remove 'scale' from non-numeric column definitions.
  2. For character lengths use 'size' (e.g. VARCHAR(255)), never 'scale'.
  3. When generating definitions programmatically, emit 'scale' only for the numeric TYPE_* set.

Example fix

// before
$column = new Column('title', [
    'type'  => Column::TYPE_VARCHAR,
    'size'  => 255,
    'scale' => 0, // throws ColumnTypeRejectsScale - VARCHAR has no scale
]);

// after
$column = new Column('title', [
    'type' => Column::TYPE_VARCHAR,
    'size' => 255,
]);
Defensive patterns

Strategy: type-guard

Validate before calling

$scaleTypes = [
    Column::TYPE_BIGINTEGER, Column::TYPE_DECIMAL, Column::TYPE_DOUBLE,
    Column::TYPE_FLOAT, Column::TYPE_INTEGER, Column::TYPE_MEDIUMINTEGER,
    Column::TYPE_SMALLINTEGER, Column::TYPE_TINYINTEGER,
];
if (isset($definition['scale']) && !in_array($definition['type'], $scaleTypes, true)) {
    unset($definition['scale']); // or throw your own error
}
$column = new Column('title', $definition);

Type guard

function typeSupportsScale(int $type): bool
{
    return in_array($type, [
        Column::TYPE_BIGINTEGER, Column::TYPE_DECIMAL, Column::TYPE_DOUBLE,
        Column::TYPE_FLOAT, Column::TYPE_INTEGER, Column::TYPE_MEDIUMINTEGER,
        Column::TYPE_SMALLINTEGER, Column::TYPE_TINYINTEGER,
    ], true);
}

Prevention

When it happens

Trigger: new Column('name', ['type' => Column::TYPE_VARCHAR, 'scale' => 2]); a generic definition template that includes scale applied to every column; describeColumns round-trips where scale was carried onto non-numeric columns.

Common situations: Reusable column blueprints applied to all fields; migrations generated by cloning a DECIMAL column definition; config formats that always emit precision/scale pairs; copy-paste from a numeric column.

Related errors


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