n8n-io/n8n · error · TypeORMError

Supplied unique constraint was not found in table ${table.na

Error message

Supplied unique constraint was not found in table ${table.name}

What it means

dropUniqueConstraint() resolves the unique constraint by name (or object) against the cached table; if none matches it throws TypeORMError. The unique constraint you are trying to drop does not exist in the table definition TypeORM has loaded.

Source

Thrown at packages/@n8n/typeorm/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts:791

		);
		await this.recreateTable(changedTable, table);
	}

	/**
	 * Drops an unique constraint.
	 */
	async dropUniqueConstraint(
		tableOrName: Table | string,
		uniqueOrName: TableUnique | string,
	): Promise<void> {
		const table = InstanceChecker.isTable(tableOrName)
			? tableOrName
			: await this.getCachedTable(tableOrName);
		const uniqueConstraint = InstanceChecker.isTableUnique(uniqueOrName)
			? uniqueOrName
			: table.uniques.find((u) => u.name === uniqueOrName);
		if (!uniqueConstraint)
			throw new TypeORMError(`Supplied unique constraint was not found in table ${table.name}`);

		await this.dropUniqueConstraints(table, [uniqueConstraint]);
	}

	/**
	 * Creates an unique constraints.
	 */
	async dropUniqueConstraints(
		tableOrName: Table | string,
		uniqueConstraints: TableUnique[],
	): Promise<void> {
		const table = InstanceChecker.isTable(tableOrName)
			? tableOrName
			: await this.getCachedTable(tableOrName);

		// clone original table and remove unique constraints from cloned table
		const changedTable = table.clone();
		uniqueConstraints.forEach((uniqueConstraint) =>

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Resolve the actual constraint name from the live schema — SQLite may auto-name it, so list uniques first via getTable().
  2. Make the drop idempotent — check existence first.
  3. Re-fetch the table via getTable() if metadata may be stale.

Example fix

// before
await queryRunner.dropUniqueConstraint('user', 'UQ_user_email');

// after
const table = await queryRunner.getTable('user');
if (table?.uniques.some((u) => u.name === 'UQ_user_email')) {
  await queryRunner.dropUniqueConstraint(table!, 'UQ_user_email');
}
Defensive patterns

Strategy: validation

Validate before calling

const table = await queryRunner.getTable('user');
if (table?.uniques.some((u) => u.name === 'UQ_user_email')) {
  await queryRunner.dropUniqueConstraint(table!, 'UQ_user_email');
}

Type guard

const uniqueExists = async (qr: QueryRunner, tableName: string, name: string): Promise<boolean> =>
  Boolean((await qr.getTable(tableName))?.uniques.some((u) => u.name === name));

Prevention

When it happens

Trigger: Calling dropUniqueConstraint(table, 'constraintName') where 'constraintName' is not present in table.uniques of the cached table.

Common situations: Re-running a migration that already dropped it, a typo in the constraint name (SQLite often auto-generates these names), or stale cached metadata.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/ccf31cb3e15c6d71. Report an issue: GitHub.