phalcon/cphalcon · error · Phalcon\Db\Exceptions\ReferencedColumnCountMismatch

Number of columns is not equals than the number of columns…

Error message

Number of columns is not equals than the number of columns referenced

What it means

Thrown by Phalcon\Db\Reference::__construct when the number of local columns does not match the number of referenced columns in a foreign-key/reference definition. Each local column must pair with exactly one referenced column.

Solutions

  1. Make count(columns) equal count(referencedColumns) in the reference definition array
  2. Verify the FK DDL you are mirroring: a composite FK over two columns needs two referenced columns
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phalcon/Db/Reference.zep:142 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at phalcon/Db/Reference.zep:142

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

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

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

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

        if unlikely count(columns) != count(referencedColumns) {
            throw new ReferencedColumnCountMismatch();
        }
    }

    /**
     * Local reference columns
     */
    public function getColumns() -> array
    {
        return this->columns;
    }

    /**
     * Constraint name
     */
    public function getName() -> string
    {
        return this->name;
    }

View on GitHub (pinned to b7419de9cd)