typeorm/typeorm · error · TypeORMError

Entities ${entityMetadata.name} and ${sameDiscriminatorValue

Error message

Entities ${entityMetadata.name} and ${sameDiscriminatorValueEntityMetadata.name} have the same discriminator values. Make sure they are different while using the @ChildEntity decorator.

What it means

Two child entities that share the same base table and the same discriminator value would be indistinguishable in queries, so validation throws. The check compares `tableName` and `discriminatorValue` across entities sharing an inheritance tree.

Source

Thrown at src/metadata-builder/EntityMetadataValidator.ts:117

            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,
                        )
                    )
                })
            if (sameDiscriminatorValueEntityMetadata)
                throw new TypeORMError(
                    `Entities ${entityMetadata.name} and ${sameDiscriminatorValueEntityMetadata.name} have the same discriminator values. Make sure they are different while using the @ChildEntity decorator.`,
                )
        }

        if (!(driver.options.type === "mongodb")) {
            entityMetadata.columns
                .filter((column) => !column.isVirtualProperty)
                .forEach((column) => {
                    const normalizedColumn = driver.normalizeType(
                        column,
                    ) as ColumnType
                    if (!driver.supportedDataTypes.includes(normalizedColumn))
                        throw new DataTypeNotSupportedError(
                            column,
                            normalizedColumn,
                            driver.options.type,
                        )
                    if (

View on GitHub (pinned to 04ff4daedc)

Solutions

  1. Give each child entity a unique discriminator value
  2. If two classes should collapse to one type, merge them into a single child entity

Example fix

// before
@ChildEntity('user') class Admin extends User {}
@ChildEntity('user') class Guest extends User {}
// after
@ChildEntity('admin') class Admin extends User {}
@ChildEntity('guest') class Guest extends User {}
Defensive patterns

Strategy: validation

Validate before calling

function assertUniqueDiscriminatorValues(metadatas: EntityMetadata[]) {
  const seen = new Map<string, string>()
  for (const m of metadatas) {
    if (m.inheritancePattern !== 'STI' && m.tableType !== 'entity-child') continue
    const key = `${m.tableName}::${m.discriminatorValue}`
    if (seen.has(key)) throw new Error(`duplicate discriminator value ${m.discriminatorValue} on table ${m.tableName}`)
    seen.set(key, m.name)
  }
}

Prevention

When it happens

Trigger: `@ChildEntity('user')` on two classes that inherit from the same base entity.

Common situations: Copy-pasting a child entity and forgetting to change its discriminator value; merging entity hierarchies.

Related errors


AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03). Data as JSON: /data/errors/883f281ff6ce7bbe.json. Report an issue: GitHub.