sequelize/sequelize · error · Error

Add constraint queries are not supported by ${this.dialect.n

Error message

Add constraint queries are not supported by ${this.dialect.name} dialect

What it means

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.

Source

Thrown at packages/core/src/abstract-dialect/query-generator-typescript.ts:364

        REMOVE_COLUMN_QUERY_SUPPORTABLE_OPTIONS,
        this.dialect.supports.removeColumn,
        options,
      );
    }

    return joinSQLFragments([
      'ALTER TABLE',
      this.quoteTable(tableName),
      'DROP COLUMN',
      options?.ifExists ? 'IF EXISTS' : '',
      this.quoteIdentifier(columnName),
      options?.cascade ? 'CASCADE' : '',
    ]);
  }

  addConstraintQuery(tableName: TableOrModel, options: AddConstraintQueryOptions): string {
    if (!this.dialect.supports.constraints.add) {
      throw new Error(`Add constraint queries are not supported by ${this.dialect.name} dialect`);
    }

    return joinSQLFragments([
      'ALTER TABLE',
      this.quoteTable(tableName),
      'ADD',
      this.#internals.getConstraintSnippet(tableName, options),
    ]);
  }

  removeConstraintQuery(
    tableName: TableOrModel,
    constraintName: string,
    options?: RemoveConstraintQueryOptions,
  ) {
    if (!this.dialect.supports.constraints.remove) {
      throw new Error(
        `Remove constraint queries are not supported by ${this.dialect.name} dialect`,

View on GitHub (pinned to 7e1deec499)

Solutions

  1. Check sequelize.dialect.supports.constraints.add before issuing addConstraint.
  2. Define the constraint inline in the model definition / CREATE TABLE instead of via a migration step.
  3. Switch to a dialect that supports ADD CONSTRAINT if your schema relies on incremental constraint management.

Example fix

// before
await queryInterface.addConstraint('users', {
  type: 'UNIQUE',
  fields: ['email'],
});

// after
if (sequelize.dialect.supports.constraints.add) {
  await queryInterface.addConstraint('users', {
    type: 'UNIQUE',
    fields: ['email'],
  });
} else {
  await sequelize.query(
    'CREATE UNIQUE INDEX users_email_unique ON users (email)'
  );
}
Defensive patterns

Strategy: validation

Validate before calling

if (!sequelize.dialect.supports.constraints?.add) {
  throw new Error(
    `${sequelize.dialect.name} cannot add constraints via ALTER TABLE`
  );
}
await queryInterface.addConstraint(table, opts);

Type guard

function canAddConstraint(seq: Sequelize): boolean {
  return Boolean(seq.dialect.supports.constraints?.add);
}

Prevention

When it happens

Trigger: Calling queryInterface.addConstraint(table, { type: 'CHECK', ... }) (or any constraint type) on a dialect whose dialect.ts sets supports.constraints.add: false.

Common situations: A dialect that only allows constraints inline in CREATE TABLE. Mixing a constraints-heavy migration suite onto a minimal/embedded dialect.

Related errors


AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03). Data as JSON: /data/errors/f13f7d2f3864f97d.json. Report an issue: GitHub.