{"id":"f13f7d2f3864f97d","repo":"sequelize/sequelize","slug":"add-constraint-queries-are-not-supported-by-this","errorCode":null,"errorMessage":"Add constraint queries are not supported by ${this.dialect.name} dialect","messagePattern":"Add constraint queries are not supported by (.+?) dialect","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/abstract-dialect/query-generator-typescript.ts","lineNumber":364,"sourceCode":"        REMOVE_COLUMN_QUERY_SUPPORTABLE_OPTIONS,\n        this.dialect.supports.removeColumn,\n        options,\n      );\n    }\n\n    return joinSQLFragments([\n      'ALTER TABLE',\n      this.quoteTable(tableName),\n      'DROP COLUMN',\n      options?.ifExists ? 'IF EXISTS' : '',\n      this.quoteIdentifier(columnName),\n      options?.cascade ? 'CASCADE' : '',\n    ]);\n  }\n\n  addConstraintQuery(tableName: TableOrModel, options: AddConstraintQueryOptions): string {\n    if (!this.dialect.supports.constraints.add) {\n      throw new Error(`Add constraint queries are not supported by ${this.dialect.name} dialect`);\n    }\n\n    return joinSQLFragments([\n      'ALTER TABLE',\n      this.quoteTable(tableName),\n      'ADD',\n      this.#internals.getConstraintSnippet(tableName, options),\n    ]);\n  }\n\n  removeConstraintQuery(\n    tableName: TableOrModel,\n    constraintName: string,\n    options?: RemoveConstraintQueryOptions,\n  ) {\n    if (!this.dialect.supports.constraints.remove) {\n      throw new Error(\n        `Remove constraint queries are not supported by ${this.dialect.name} dialect`,","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/sequelize/sequelize/blob/7e1deec499d5afbb8d1877c2f4d545cead1214ec/packages/core/src/abstract-dialect/query-generator-typescript.ts#L346-L382","documentation":"Thrown by addConstraintQuery when the dialect reports supports.constraints.add === false. Adding constraints via ALTER TABLE ... ADD CONSTRAINT is a dialect capability; dialects that disable it cannot service queryInterface.addConstraint calls, so the generator rejects the request up front rather than emit invalid SQL.","triggerScenarios":"Calling queryInterface.addConstraint(table, { type: 'CHECK', ... }) (or any constraint type) on a dialect whose dialect.ts sets supports.constraints.add: false.","commonSituations":"A dialect that only allows constraints inline in CREATE TABLE. Mixing a constraints-heavy migration suite onto a minimal/embedded dialect.","solutions":["Check sequelize.dialect.supports.constraints.add before issuing addConstraint.","Define the constraint inline in the model definition / CREATE TABLE instead of via a migration step.","Switch to a dialect that supports ADD CONSTRAINT if your schema relies on incremental constraint management."],"exampleFix":"// before\nawait queryInterface.addConstraint('users', {\n  type: 'UNIQUE',\n  fields: ['email'],\n});\n\n// after\nif (sequelize.dialect.supports.constraints.add) {\n  await queryInterface.addConstraint('users', {\n    type: 'UNIQUE',\n    fields: ['email'],\n  });\n} else {\n  await sequelize.query(\n    'CREATE UNIQUE INDEX users_email_unique ON users (email)'\n  );\n}","handlingStrategy":"validation","validationCode":"if (!sequelize.dialect.supports.constraints?.add) {\n  throw new Error(\n    `${sequelize.dialect.name} cannot add constraints via ALTER TABLE`\n  );\n}\nawait queryInterface.addConstraint(table, opts);","typeGuard":"function canAddConstraint(seq: Sequelize): boolean {\n  return Boolean(seq.dialect.supports.constraints?.add);\n}","tryCatchPattern":null,"preventionTips":["Define constraints inline in createTable when targeting minimal dialects.","Branch constraint management on the supports.constraints.* map."],"tags":["dialect-capability","constraints","query-interface","migration"],"analyzedSha":"7e1deec499d5afbb8d1877c2f4d545cead1214ec","analyzedAt":"2026-08-03T18:58:44.549Z","schemaVersion":2}