typeorm/typeorm · error · TypeORMError

SqlServer does not support exclusion constraints.

Error message

SqlServer does not support exclusion constraints.

What it means

Thrown unconditionally by SqlServerQueryRunner.createExclusionConstraint. SQL Server has no exclusion constraint feature (this is PostgreSQL-specific, e.g. EXCLUDE USING gist). The method exists to satisfy the QueryRunner interface contract but always throws to signal the feature is unsupported.

Source

Thrown at src/driver/sqlserver/SqlServerQueryRunner.ts:2582

        ifExists?: boolean,
    ): Promise<void> {
        const promises = checkConstraints.map((checkConstraint) =>
            this.dropCheckConstraint(tableOrName, checkConstraint, ifExists),
        )
        await Promise.all(promises)
    }

    /**
     * Creates a new exclusion constraint.
     *
     * @param tableOrName
     * @param exclusionConstraint
     */
    async createExclusionConstraint(
        tableOrName: Table | string,
        exclusionConstraint: TableExclusion,
    ): Promise<void> {
        throw new TypeORMError(
            `SqlServer does not support exclusion constraints.`,
        )
    }

    /**
     * Creates a new exclusion constraints.
     *
     * @param tableOrName
     * @param exclusionConstraints
     */
    async createExclusionConstraints(
        tableOrName: Table | string,
        exclusionConstraints: TableExclusion[],
    ): Promise<void> {
        throw new TypeORMError(
            `SqlServer does not support exclusion constraints.`,
        )
    }

View on GitHub (pinned to 04ff4daedc)

Solutions

  1. Remove the exclusion constraint definition from entities/migrations targeting SQL Server.
  2. Switch to PostgreSQL if exclusion constraints are a hard requirement.
  3. Replace with a SQL Server equivalent: a trigger + check constraint combination, or a unique filtered index depending on the use case.
  4. Add a driver-capability guard before calling createExclusionConstraint.

Example fix

// before
await queryRunner.createExclusionConstraint(table, {
  name: "EX_room_booking",
  expression: "USING gist (room WITH =, tstzrange(start, "end") WITH &&)",
})
// after — guard by driver type, or omit for sqlserver
if (queryRunner.connection.options.type !== "mssql") {
  await queryRunner.createExclusionConstraint(table, exclusionConstraint)
}
Defensive patterns

Strategy: validation

Validate before calling

const driverType = queryRunner.connection.options.type
if (driverType === 'mssql') {
  throw new Error('Exclusion constraints are unsupported on SQL Server — use Postgres or an alternative.')
}
await queryRunner.createExclusionConstraint(table, constraint)

Type guard

function supportsExclusionConstraints(driverType: string): boolean {
  return driverType === 'postgres'
}

Try / catch

try {
  await queryRunner.createExclusionConstraint(table, constraint)
} catch (e) {
  if (e instanceof TypeORMError && /does not support exclusion constraints/.test(e.message)) {
    // skip on unsupported drivers
    return
  }
  throw e
}

Prevention

When it happens

Trigger: Calling queryRunner.createExclusionConstraint(table, exclusionConstraint) on a SQL Server connection. Also triggered indirectly if shared schema-builder code or a migration attempts to create exclusion constraints generically across all supported drivers.

Common situations: Porting a PostgreSQL-based schema/migration to SQL Server without removing exclusion constraints; using a generic migration that iterates all constraint types; library abstractions that call createExclusionConstraints without driver capability checks.

Related errors


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