n8n-io/n8n · error · TypeORMError
Entity ${entityMetadata.name} has multiple primary columns w
Error message
Entity ${entityMetadata.name} has multiple primary columns with different constraint names. Constraint names should be the equal. What it means
Thrown by EntityMetadataValidator.validate when an entity has more than one primary column but they do not all share the same primaryKeyConstraintName. The check uses entityMetadata.primaryColumns.every comparing each column's primaryKeyConstraintName to the first; mismatch triggers TypeORMError. Without a shared constraint name the database cannot create a single composite PK constraint.
Source
Thrown at packages/@n8n/typeorm/src/metadata-builder/EntityMetadataValidator.ts:63
}
/**
* Validates given entity metadata.
*/
validate(entityMetadata: EntityMetadata, allEntityMetadatas: EntityMetadata[], driver: Driver) {
// check if table metadata has an id
if (!entityMetadata.primaryColumns.length && !entityMetadata.isJunction)
throw new MissingPrimaryColumnError(entityMetadata);
// if entity has multiple primary keys and uses custom constraint name,
// then all primary keys should have the same constraint name
if (entityMetadata.primaryColumns.length > 1) {
const areConstraintNamesEqual = entityMetadata.primaryColumns.every(
(columnMetadata, i, columnMetadatas) =>
columnMetadata.primaryKeyConstraintName === columnMetadatas[0].primaryKeyConstraintName,
);
if (!areConstraintNamesEqual) {
throw new TypeORMError(
`Entity ${entityMetadata.name} has multiple primary columns with different constraint names. Constraint names should be the equal.`,
);
}
}
// validate if table is using inheritance it has a discriminator
// also validate if discriminator values are not empty and not repeated
if (
entityMetadata.inheritancePattern === 'STI' ||
entityMetadata.tableType === 'entity-child'
) {
if (!entityMetadata.discriminatorColumn)
throw new TypeORMError(
`Entity ${entityMetadata.name} using single-table inheritance, it should also have a discriminator column. Did you forget to put discriminator column options?`,
);
if (typeof entityMetadata.discriminatorValue === 'undefined')
throw new TypeORMError(View on GitHub (pinned to 5ac6606e81)
Solutions
- Set the identical primaryKeyConstraintName on every @PrimaryColumn of the composite key.
- If you do not need a custom name, omit the option on all of them (they will all be undefined and pass the every() check).
- Audit the entity and align the option values to a single constant.
Example fix
// before
@Entity()
export class Member {
@PrimaryColumn({ primaryKeyConstraintName: 'pk_org' }) orgId: number;
@PrimaryColumn({ primaryKeyConstraintName: 'pk_user' }) userId: number;
}
// after
@Entity()
export class Member {
@PrimaryColumn({ primaryKeyConstraintName: 'pk_member' }) orgId: number;
@PrimaryColumn({ primaryKeyConstraintName: 'pk_member' }) userId: number;
} Defensive patterns
Strategy: validation
Validate before calling
function assertCompositePkConstraintNamesAligned(dataSource: DataSource): string[] {
const problems: string[] = [];
for (const meta of dataSource.entityMetadatas) {
if (meta.primaryColumns.length <= 1) continue;
const names = meta.primaryColumns.map((c) => c.primaryKeyConstraintName);
if (!names.every((n) => n === names[0])) {
problems.push(`${meta.targetName} primary columns have mismatched constraint names: ${JSON.stringify(names)}`);
}
}
return problems;
} Try / catch
try {
await dataSource.initialize();
} catch (err) {
if (err.message.includes('multiple primary columns with different constraint names')) {
// align primaryKeyConstraintName across composite PK columns
}
throw err;
} Prevention
- Define composite PKs with a single shared const for primaryKeyConstraintName.
- Run the post-init constraint-name validator in CI.
- When adding a new column to a composite PK, copy the constraint-name option from a sibling column.
When it happens
Trigger: Declaring multiple @PrimaryColumn decorators with different primaryKeyConstraintName values, or mixing some columns that set the option with others that leave it undefined.
Common situations: Adopting named PK constraints (e.g. for cross-database consistency) on only some columns of a composite key; copy-pasting columns from different entities.
Related errors
- Cannot use given entity id "${id}" because "${metadata.targe
- Entity "${entityMetadata.name}" does not have a primary colu
- Azure Blob container name not configured. Please set `N8N_EX
- External storage bucket name not configured. Please set `N8N
- Unknown agents module: "${moduleName}". ${validTokens ? `Val
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/5066047f60a6c393.
Report an issue: GitHub.