{"id":"e3f1fd0f460ed4ee","repo":"typeorm/typeorm","slug":"sqlserver-does-not-support-exclusion-constraints","errorCode":null,"errorMessage":"SqlServer does not support exclusion constraints.","messagePattern":"SqlServer does not support exclusion constraints\\.","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"src/driver/sqlserver/SqlServerQueryRunner.ts","lineNumber":2582,"sourceCode":"        ifExists?: boolean,\n    ): Promise<void> {\n        const promises = checkConstraints.map((checkConstraint) =>\n            this.dropCheckConstraint(tableOrName, checkConstraint, ifExists),\n        )\n        await Promise.all(promises)\n    }\n\n    /**\n     * Creates a new exclusion constraint.\n     *\n     * @param tableOrName\n     * @param exclusionConstraint\n     */\n    async createExclusionConstraint(\n        tableOrName: Table | string,\n        exclusionConstraint: TableExclusion,\n    ): Promise<void> {\n        throw new TypeORMError(\n            `SqlServer does not support exclusion constraints.`,\n        )\n    }\n\n    /**\n     * Creates a new exclusion constraints.\n     *\n     * @param tableOrName\n     * @param exclusionConstraints\n     */\n    async createExclusionConstraints(\n        tableOrName: Table | string,\n        exclusionConstraints: TableExclusion[],\n    ): Promise<void> {\n        throw new TypeORMError(\n            `SqlServer does not support exclusion constraints.`,\n        )\n    }","sourceCodeStart":2564,"sourceCodeEnd":2600,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/driver/sqlserver/SqlServerQueryRunner.ts#L2564-L2600","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove the exclusion constraint definition from entities/migrations targeting SQL Server.","Switch to PostgreSQL if exclusion constraints are a hard requirement.","Replace with a SQL Server equivalent: a trigger + check constraint combination, or a unique filtered index depending on the use case.","Add a driver-capability guard before calling createExclusionConstraint."],"exampleFix":"// before\nawait queryRunner.createExclusionConstraint(table, {\n  name: \"EX_room_booking\",\n  expression: \"USING gist (room WITH =, tstzrange(start, \"end\") WITH &&)\",\n})\n// after — guard by driver type, or omit for sqlserver\nif (queryRunner.connection.options.type !== \"mssql\") {\n  await queryRunner.createExclusionConstraint(table, exclusionConstraint)\n}","handlingStrategy":"validation","validationCode":"const driverType = queryRunner.connection.options.type\nif (driverType === 'mssql') {\n  throw new Error('Exclusion constraints are unsupported on SQL Server — use Postgres or an alternative.')\n}\nawait queryRunner.createExclusionConstraint(table, constraint)","typeGuard":"function supportsExclusionConstraints(driverType: string): boolean {\n  return driverType === 'postgres'\n}","tryCatchPattern":"try {\n  await queryRunner.createExclusionConstraint(table, constraint)\n} catch (e) {\n  if (e instanceof TypeORMError && /does not support exclusion constraints/.test(e.message)) {\n    // skip on unsupported drivers\n    return\n  }\n  throw e\n}","preventionTips":["Guard exclusion-constraint creation with a driver-type check before calling.","Keep Postgres-specific constraints in driver-specific migration files.","Document which features each target database supports."],"tags":["sqlserver","unsupported-feature","exclusion-constraint"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}