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

  1. Remove 'autoIncrement' from the definition of the generated column.
  2. Keep the numeric auto-increment id as a separate column from any computed column.
  3. 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

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


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/7d6c2f93b57760fe. Report an issue: GitHub.