phalcon/cphalcon · error · ColumnTypeRejectsAutoIncrement
Column type cannot be auto-increment
Error message
Column type cannot be auto-increment
What it means
Phalcon\Db\Column allows 'autoIncrement' => true only for integer types: BIGINTEGER, INTEGER, MEDIUMINTEGER, SMALLINTEGER and TINYINTEGER. Requesting auto-increment on any other type (VARCHAR, DECIMAL, DATE, ...) throws ColumnTypeRejectsAutoIncrement before SQL generation - the database would reject it too.
Source
Thrown at phalcon/Db/Column.zep:685
/**
* Check if the field is auto-increment/serial
*/
if fetch autoIncrement, definition["autoIncrement"] {
if !autoIncrement {
let this->autoIncrement = false;
} else {
switch type {
case self::TYPE_BIGINTEGER:
case self::TYPE_INTEGER:
case self::TYPE_MEDIUMINTEGER:
case self::TYPE_SMALLINTEGER:
case self::TYPE_TINYINTEGER:
let this->autoIncrement = true;
break;
default:
throw new ColumnTypeRejectsAutoIncrement();
}
}
}
/**
* Check if the field is placed at the first position of the table
*/
if fetch first, definition["first"] {
let this->first = first;
}
/**
* Name of the column which is placed before the current field
*/
if fetch after, definition["after"] {
let this->after = after;
}
View on GitHub (pinned to b7419de9cd)
Solutions
- Remove 'autoIncrement' from non-integer key columns and generate the key in application code (e.g. UUIDs).
- Keep an integer type if you want database-side auto-increment.
- Emit 'autoIncrement' only when the type is in the integer TYPE_* set.
Example fix
// before
$column = new Column('uuid', [
'type' => Column::TYPE_VARCHAR,
'size' => 36,
'primary' => true,
'autoIncrement' => true, // throws ColumnTypeRejectsAutoIncrement
]);
// after
$column = new Column('uuid', [
'type' => Column::TYPE_VARCHAR,
'size' => 36,
'primary' => true,
]); // generate UUIDs in application code Defensive patterns
Strategy: type-guard
Validate before calling
$aiTypes = [
Column::TYPE_BIGINTEGER, Column::TYPE_INTEGER, Column::TYPE_MEDIUMINTEGER,
Column::TYPE_SMALLINTEGER, Column::TYPE_TINYINTEGER,
];
if (!empty($definition['autoIncrement'])
&& !in_array($definition['type'], $aiTypes, true)) {
unset($definition['autoIncrement']);
}
$column = new Column('uuid', $definition); Type guard
function typeSupportsAutoIncrement(int $type): bool
{
return in_array($type, [
Column::TYPE_BIGINTEGER, Column::TYPE_INTEGER, Column::TYPE_MEDIUMINTEGER,
Column::TYPE_SMALLINTEGER, Column::TYPE_TINYINTEGER,
], true);
} Prevention
- Non-integer primary keys mean application-side key generation - never autoIncrement.
- Centralize id-column blueprints so the type/autoIncrement pair is always consistent.
- When migrating int keys to UUIDs, grep schema code for autoIncrement first.
When it happens
Trigger: new Column('uuid', ['type' => Column::TYPE_VARCHAR, 'primary' => true, 'autoIncrement' => true]); copying an integer id blueprint onto a string key; autoIncrement on DECIMAL (which MySQL itself disallows).
Common situations: Switching primary keys from int to UUID/string without removing autoIncrement; generic BaseModel schemas marking every primary key auto-increment; migrations cloned from an integer-keyed table; ORM defaults leaking into custom columns.
Related errors
- Generated column cannot also be auto-increment
- Column type is required
- Column type does not support scale parameter
- Column generation expression must be a string
- Generated column cannot have a default value
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/26b46b1ac9f1d0d2.
Report an issue: GitHub.