phalcon/cphalcon · error · CheckExpressionRequired
CHECK expression is required
Error message
CHECK expression is required
What it means
Phalcon\Db\Check models a CHECK constraint. Its constructor requires definition['expression'] - the raw SQL expression placed inside CHECK (...). Without that key the object cannot represent any constraint, so construction fails with CheckExpressionRequired before name or expression are assigned.
Source
Thrown at phalcon/Db/Check.zep:72
/**
* The CHECK constraint name. An empty string indicates an unnamed
* constraint - the dialect will emit the clause without a `CONSTRAINT`
* prefix in that case.
*
* @var string
*/
protected name;
/**
* Phalcon\Db\Check constructor
*/
public function __construct( string name, array definition)
{
var expression;
if unlikely !fetch expression, definition["expression"] {
throw new CheckExpressionRequired();
}
if unlikely typeof expression != "string" || expression === "" {
throw new InvalidCheckExpression();
}
let this->name = name;
let this->expression = expression;
}
/**
* Returns the CHECK expression
*/
public function getExpression() -> string
{
return this->expression;
}
View on GitHub (pinned to b7419de9cd)
Solutions
- Add 'expression' => 'price >= 0' (any valid SQL boolean expression) to the definition array.
- Validate the key before constructing when definitions come from external config.
- Use the exact lowercase key 'expression'.
Example fix
// before
$check = new Check('chk_price', ['type' => 'check']); // throws CheckExpressionRequired
// after
$check = new Check('chk_price', ['expression' => 'price >= 0']); Defensive patterns
Strategy: validation
Validate before calling
if (!isset($definition['expression'])) {
throw new InvalidArgumentException('Check definition requires "expression"');
}
$check = new Check('chk_price', $definition); Type guard
function checkDefinitionIsValid(array $definition): bool
{
return isset($definition['expression'])
&& is_string($definition['expression'])
&& $definition['expression'] !== '';
} Prevention
- Treat constraint definitions as typed value objects, not loose arrays.
- Validate config-sourced definitions at load time, before DDL runs.
- Wrap Check construction in a small factory so the key is set in exactly one place.
When it happens
Trigger: new Check('chk_price', []) or a definition carrying only unrelated keys; typo'd keys ('expr', 'sql', 'condition'); constraint arrays built dynamically from config where the expression entry was never set.
Common situations: Schema builders converting config/annotations into Check objects; hand-written migrations where the expression line was forgotten; refactors renaming keys inconsistently between producer and consumer code.
Related errors
- The table must contain at least one column
- CHECK expression must be a non-empty string
- Column type is required
- Column type does not support scale parameter
- The index 'columns' is required in the definition array
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/cb7166be5b719707.
Report an issue: GitHub.