drizzle-team/drizzle-orm · error · Error

You can't use phone number generator with a db column length

Error message

You can't use phone number generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxPrefixLength + maxGeneratedDigits}.

What it means

Error "You can't use phone number generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxPrefixLength + maxGeneratedDigits}." thrown in drizzle-team/drizzle-orm.

Source

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

		} else {
			prefixesArray = prefixes;
			if (typeof generatedDigitsNumbers === 'number') {
				generatedDigitsNumbers = Array.from<number>({ length: prefixes.length }).fill(
					generatedDigitsNumbers,
				);
			} else if (
				generatedDigitsNumbers === undefined
				|| generatedDigitsNumbers.length === 0
			) {
				generatedDigitsNumbers = Array.from<number>({ length: prefixes.length }).fill(7);
			}
		}

		const maxPrefixLength = Math.max(...prefixesArray.map((prefix) => prefix.length));
		const maxGeneratedDigits = Math.max(...generatedDigitsNumbers);

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

		if (new Set(prefixesArray).size !== prefixesArray.length) {
			throw new Error('prefixes are not unique.');
		}

		const maxUniquePhoneNumbersCount = generatedDigitsNumbers.reduce(
			(a, b) => a + Math.pow(10, b),
			0,
		);
		if (maxUniquePhoneNumbersCount < count) {
			throw new RangeError(
				`count exceeds max number of unique phone numbers(${maxUniquePhoneNumbersCount}).`,
			);

View on GitHub (pinned to b7862528fd)

Solutions

  1. Increase the column's maximum string length to at least prefix length plus generated digits, or shorten prefixes/digits.

When it happens

Trigger: Using the phone-number generator on a column shorter than prefix + generated digits length.

Common situations: Short varchar for phone column; set max length to at least maxPrefixLength + maxGeneratedDigits.


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