phalcon/cphalcon · error · NoPrimaryKey
Source related to this model does not have a primary key…
Error message
Source related to this model does not have a primary key defined
What it means
Thrown in Builder::getPhql when using the numeric conditions shorthand: the model's source table has no primary key defined in its metadata, so no auto condition can be generated. The input at fault is a model without primary key attributes.
Solutions
- Define a primary key in the table/metadata for the model.
- Use an explicit where() condition on a unique column instead of the numeric shorthand.
- Ensure getPrimaryKeyAttributes returns the key; refresh metadata caches if the schema changed.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at phalcon/Mvc/Model/Query/Builder.zep:790 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/5a978853dc1febc2.
Report an issue: GitHub.
Appendix: source
Thrown at phalcon/Mvc/Model/Query/Builder.zep:790
}
/**
* Use a named bind parameter instead of embedding the value
* directly in the PHQL string. Embedding produces a unique
* PHQL string per ID value, causing unbounded growth of the
* internal PHQL cache in long-running processes.
*/
let this->bindParams["APK0"] = conditions,
conditions = this->autoescape(model) . "." . this->autoescape(attributeField) . " = :APK0:",
noPrimary = false;
}
}
/**
* A primary key is mandatory in these cases
*/
if unlikely noPrimary {
throw new NoPrimaryKey();
}
}
let distinct = this->distinct;
if typeof distinct == "boolean" {
if distinct {
let phql = "SELECT DISTINCT ";
} else {
let phql = "SELECT ALL ";
}
} else {
let phql = "SELECT ";
}
let columns = this->columns;
if columns !== null {View on GitHub (pinned to b7419de9cd)