n8n-io/n8n · error · TypeORMError
Entity ${entityMetadata.name} using single-table inheritance
Error message
Entity ${entityMetadata.name} using single-table inheritance, it should also have a discriminator column. Did you forget to put discriminator column options? What it means
Thrown by EntityMetadataValidator.validate inside the single-table-inheritance branch (inheritancePattern === 'STI' or tableType === 'entity-child') when no discriminatorColumn exists on the metadata. STI requires a discriminator column on the root entity so TypeORM can store the concrete subclass per row.
Source
Thrown at packages/@n8n/typeorm/src/metadata-builder/EntityMetadataValidator.ts:76
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(
`Entity ${entityMetadata.name} has an undefined discriminator value. Discriminator value should be defined.`,
);
const sameDiscriminatorValueEntityMetadata = allEntityMetadatas.find((metadata) => {
return (
metadata !== entityMetadata &&
(metadata.inheritancePattern === 'STI' || metadata.tableType === 'entity-child') &&
metadata.tableName === entityMetadata.tableName &&
metadata.discriminatorValue === entityMetadata.discriminatorValue &&
metadata.inheritanceTree.some(
(parent) => entityMetadata.inheritanceTree.indexOf(parent) !== -1,
)
);View on GitHub (pinned to 5ac6606e81)
Solutions
- Add @DiscriminatorColumn({ name: 'type', type: 'string' }) to the root abstract/base entity of the hierarchy.
- Confirm inheritancePattern resolves to STI (TypeORM infers it from extend patterns); if you did not intend STI, remove the @ChildEntity decorator or the extends chain.
- Re-run schema sync after the change so the discriminator column is materialized in the DB.
Example fix
// before
@Entity()
export abstract class Content {
@PrimaryGeneratedColumn() id: number;
}
@Entity()
export class Article extends Content {}
// after
@Entity()
@DiscriminatorColumn({ name: 'kind', type: 'string' })
export abstract class Content {
@PrimaryGeneratedColumn() id: number;
}
@ChildEntity()
export class Article extends Content {} Defensive patterns
Strategy: validation
Validate before calling
function assertStiHasDiscriminator(dataSource: DataSource): string[] {
const problems: string[] = [];
for (const meta of dataSource.entityMetadatas) {
const isSti = meta.inheritancePattern === 'STI' || meta.tableType === 'entity-child';
if (isSti && !meta.discriminatorColumn) {
problems.push(`${meta.targetName} uses STI but has no discriminator column`);
}
}
return problems;
} Try / catch
try {
await dataSource.initialize();
} catch (err) {
if (err.message.includes('single-table inheritance') && err.message.includes('discriminator column')) {
// add @DiscriminatorColumn on the root entity
}
throw err;
} Prevention
- Treat STI hierarchies as a single unit: root must carry @DiscriminatorColumn before any @ChildEntity is added.
- Add an integration test that boots the DataSource for every STI tree in the app.
- Document the STI root prominently so contributors do not add children to a non-STI base.
When it happens
Trigger: Using @SingleEntityInheritance / extending an @Entity class (or marking @ChildEntity) without declaring @DiscriminatorColumn on the root entity, or declaring it on the child instead of the root.
Common situations: Adding a child entity to an STI hierarchy whose parent lacks a discriminator; refactoring an entity into STI and forgetting the discriminator decorator.
Related errors
- Entity ${entityMetadata.name} has an undefined discriminator
- Entities ${entityMetadata.name} and ${sameDiscriminatorValue
- Index ${indexName}contains column that is missing in the ent
- Cannot find relation ${propertyPath}. Wrong relation specifi
- Cannot find relation ${propertyPath}. Wrong relation specifi
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/2bac1cf20c3a246b.
Report an issue: GitHub.