phalcon/cphalcon · error · Phalcon\Mvc\Model\Query\Exceptions\InsertColumnCountMismatch

The column count does not match the values count

Error message

The column count does not match the values count

What it means

Query::prepareInsert() compares the number of field names in the INSERT against the number of value expressions; if counts differ, InsertColumnCountMismatch is thrown. The faulty input is the PHQL INSERT statement whose column list and VALUES list have different lengths.

Solutions

  1. Make the INSERT column list and VALUES list the same length
  2. Bind each value with a matching placeholder
  3. Rebuild the INSERT programmatically to guarantee pairing

Example fix

INSERT INTO Robots (name, price) VALUES (:name:, :price:) -- equal counts
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Thrown at phalcon/Mvc/Model/Query.zep:1001 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/f1def237cbc6b5b0. Report an issue: GitHub.

Appendix: source

Thrown at phalcon/Mvc/Model/Query.zep:1001

        if !fetch fields, intermediate["fields"] {
            let automaticFields = true,
                fields = attributes;

            if Settings::get("orm.column_renaming") {
                let columnMap = metaData->getColumnMap(model);
            } else {
                let columnMap = null;
            }
        }

        let values = intermediate["values"];

        /**
         * The number of calculated values must be equal to the number of fields
         * in the model
         */
        if unlikely count(fields) != count(values) {
            throw new InsertColumnCountMismatch();
        }

        /**
         * Get the dialect to resolve the SQL expressions
         */
        let dialect = connection->getDialect();

        let insertValues = [];
        for number, value in values {
            let exprValue = value["value"];

            switch value["type"] {

                case PHQL_T_STRING:
                case PHQL_T_INTEGER:
                case PHQL_T_DOUBLE:
                    let insertValue = dialect->getSqlExpression(exprValue);
                    break;

View on GitHub (pinned to b7419de9cd)