drizzle-team/drizzle-orm · error · RangeError

count exceeds max number of unique company names(${maxUnique

Error message

count exceeds max number of unique company names(${maxUniqueCompanyNameNumber}).

What it means

GenerateUniqueCompanyName draws from a finite combinatorial space of last-name, suffix, and template permutations. The maximum unique names equals lastNames.length * companyNameSuffixes.length + lastNames.length^2 + lastNames.length^2 + lastNames.length^3. When the requested row count exceeds this ceiling there are simply not enough distinct names, so init() throws a RangeError.

Source

Thrown at drizzle-seed/src/services/Generators.ts:2680

	private state: {
		rng: prand.RandomGenerator;
		templates: {
			template: string;
			placeholdersCount: number;
			indicesGen: GenerateUniqueInt;
			maxUniqueCompanyNameNumber: number;
			count: number;
			arraysToChooseFrom: string[][];
		}[];
	} | undefined;
	public override isUnique = true;

	override init({ count, seed }: { count: number; seed: number }) {
		const maxUniqueCompanyNameNumber = lastNames.length * companyNameSuffixes.length + Math.pow(lastNames.length, 2)
			+ Math.pow(lastNames.length, 2) + Math.pow(lastNames.length, 3);
		if (count > maxUniqueCompanyNameNumber) {
			throw new RangeError(
				`count exceeds max number of unique company names(${maxUniqueCompanyNameNumber}).`,
			);
		}

		// max( { template: '#', placeholdersCount: 1 }, { template: '#, # and #', placeholdersCount: 3 } )
		const maxCompanyNameLength = Math.max(
			maxLastNameLength + maxCompanyNameSuffixLength + 1,
			3 * maxLastNameLength + 7,
		);
		if (this.stringLength !== undefined && this.stringLength < maxCompanyNameLength) {
			throw new Error(
				`You can't use company name generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxCompanyNameLength}.`,
			);
		}

		const rng = prand.xoroshiro128plus(seed);
		// when count reach maxUniqueCompanyNameNumber template will be deleted from array
		const templates = [

View on GitHub (pinned to b7862528fd)

Solutions

  1. Lower the table's count to at or below the maxUniqueCompanyNameNumber printed in the error.
  2. Remove the unique constraint on the column if uniqueness is not truly required, which lets the non-unique GenerateCompanyName be used.
  3. Switch the column to a generator with a larger combinatorial space, such as GenerateUniqueString.

Example fix

// before
await seed(db, { schema }, { count: 500000 });
// after
await seed(db, { schema }, { count: 10000 });
Defensive patterns

Strategy: validation

Validate before calling

// The unique company-name space is finite. Check count before seeding.
// maxUniqueCompanyNameNumber = L*S + L^2 + L^2 + L^3 (L=lastNames.length, S=suffixes.length)
// Use a conservative cap; the error gives the exact number.
const SAFE_UNIQUE_COMPANY_NAME_CAP = 500_000; // adjust after reading the error's actual ceiling
function countFitsUniqueCompanyNames(count: number): boolean {
  return count <= SAFE_UNIQUE_COMPANY_NAME_CAP;
}

Prevention

When it happens

Trigger: Setting a high count (e.g. 500000) on a table whose column has a unique constraint and is auto-assigned (or refined to) GenerateUniqueCompanyName, so that count > maxUniqueCompanyNameNumber.

Common situations: Seeding a large production-scale dataset where a unique company-name column is required but the count outgrows the built-in name dictionary; stress-test scripts that bump count without checking generator limits.

Related errors


AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03). Data as JSON: /data/errors/8a63771a4b40ecd9.json. Report an issue: GitHub.