phalcon/cphalcon · error · MissingModelAttribute

The model ' ' does not have the attribute ' ', when…

Error message

The model '{model}' does not have the attribute '{attribute}', when preparing: {phql}

What it means

Thrown in Query::prepareInsert while validating the explicit field list: a field named in INSERT INTO Model (fields) is not an attribute of the target model per its metadata, so the insert would target a nonexistent column. The input at fault is the field name in the PHQL.

Solutions

  1. Use model attribute (property) names, not raw database column names, in the INSERT field list.
  2. Refresh model metadata caches if the model recently gained the attribute.
  3. Remove the unknown field or add it to the model.
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

            ];
        }

        let sqlInsert = [
            "model": modelName,
            "table": source
        ];

        let metaData = this->metaData;

        if fetch fields, ast["fields"] {
            let sqlFields = [];

            for field in fields {
                let name = field["name"];

                // Check that inserted fields are part of the model
                if unlikely !metaData->hasAttribute(model, name) {
                    throw new MissingModelAttribute(modelName, name, this->phql);
                }

                // Add the file to the insert list
                let sqlFields[] = name;
            }

            let sqlInsert["fields"] = sqlFields;
        }

        let sqlInsert["values"] = exprValues;

        return sqlInsert;
    }

    /**
     * Analyzes a SELECT intermediate code and produces an array to be executed later
     */
    final protected function prepareSelect(var ast = null, bool merge = false) -> array

View on GitHub (pinned to b7419de9cd)