phalcon/cphalcon · error · GeneratedAutoIncrementConflict
Generated column cannot also be auto-increment
Error message
Generated column cannot also be auto-increment
What it means
A column cannot be both generated (computed by the database) and auto-increment - the two value-generation strategies are mutually exclusive. Phalcon\Db\Column enforces this in the constructor: after validating that 'generated' is a string, an 'autoIncrement' => true definition combined with a non-null 'generated' throws GeneratedAutoIncrementConflict.
Source
Thrown at phalcon/Db/Column.zep:730
* Get the column comment
*/
if fetch comment, definition["comment"] {
let this->comment = comment;
}
/**
* Generated/computed column expression. When a non-empty string is
* provided the column is marked as generated and DEFAULT /
* AUTO_INCREMENT are no longer compatible at the dialect level.
*/
if fetch generated, definition["generated"] {
if generated !== null {
if unlikely typeof generated != "string" {
throw new InvalidGenerationExpression();
}
if unlikely this->autoIncrement {
throw new GeneratedAutoIncrementConflict();
}
if unlikely this->defaultValue !== null {
throw new GeneratedDefaultConflict();
}
let this->generated = generated;
}
}
/**
* Storage flag for generated columns. true = STORED, false = VIRTUAL.
*/
if fetch generationStored, definition["generationStored"] {
let this->generationStored = (bool) generationStored;
}
/**View on GitHub (pinned to b7419de9cd)
Solutions
- Remove 'autoIncrement' from the definition of the generated column.
- Keep the numeric auto-increment id as a separate column from any computed column.
- When marking a column generated, strip both 'autoIncrement' and 'default' programmatically.
Example fix
// before
$column = new Column('id', [
'type' => Column::TYPE_INTEGER,
'primary' => true,
'autoIncrement' => true,
'generated' => 'some_expr', // throws GeneratedAutoIncrementConflict
]);
// after - computed column, no auto-increment
$column = new Column('id', [
'type' => Column::TYPE_INTEGER,
'primary' => true,
'generated' => 'some_expr',
]); Defensive patterns
Strategy: validation
Validate before calling
if (isset($definition['generated']) && $definition['generated'] !== null
&& !empty($definition['autoIncrement'])) {
throw new InvalidArgumentException('A generated column cannot be auto-increment');
}
$column = new Column('id', $definition); Prevention
- One generation mechanism per column: auto-increment, default, or generated - never two.
- Review id-column blueprints before adding computed expressions.
- Validate definitions against a conflict matrix in your schema builder.
When it happens
Trigger: new Column('id', ['type' => Column::TYPE_INTEGER, 'autoIncrement' => true, 'generated' => '...']); copying a standard id blueprint and then adding a generation expression; attempting to make an identity column also computed.
Common situations: Extending default model schemas (which ship autoIncrement id columns) with generated columns; migration refactors converting a column to computed without stripping the old flag; definition mergers that union both keys.
Related errors
- Generated column cannot have a default value
- Column type cannot be auto-increment
- Column generation expression must be a string
- Column type is required
- Column type does not support scale parameter
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/7d6c2f93b57760fe.
Report an issue: GitHub.