drizzle-team/drizzle-orm · error · Error

count exceeds max number of unique countries.

Error message

count exceeds max number of unique countries.

What it means

Error "count exceeds max number of unique countries." thrown in drizzle-team/drizzle-orm.

Source

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

		[idx, this.state.rng] = prand.uniformIntDistribution(0, countries.length - 1, this.state.rng);
		const country = countries[idx] as string;

		return country;
	}
}

export class GenerateUniqueCountry extends AbstractGenerator<{ isUnique?: boolean }> {
	static override readonly entityKind: string = 'GenerateUniqueCountry';

	private state: {
		genIndicesObj: GenerateUniqueInt;
	} | undefined;
	public override isUnique = true;

	override init({ count, seed }: { count: number; seed: number }) {
		if (count > countries.length) {
			throw new Error('count exceeds max number of unique countries.');
		}

		if (this.stringLength !== undefined && this.stringLength < maxCountryLength) {
			throw new Error(
				`You can't use country generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxCountryLength}.`,
			);
		}

		const genIndicesObj = new GenerateUniqueInt({ minValue: 0, maxValue: countries.length - 1 });
		genIndicesObj.init({ count, seed });

		this.state = { genIndicesObj };
	}

	generate() {
		if (this.state === undefined) {
			throw new Error('state is not defined.');
		}

View on GitHub (pinned to b7862528fd)

Solutions

  1. Reduce the requested unique country count or drop the unique constraint.

When it happens

Trigger: Requesting more unique countries than exist in the country pool.

Common situations: Unique country column with count greater than the number of countries.


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