drizzle-team/drizzle-orm · error · Error

You can't use postcode generator with a db column length res

Error message

You can't use postcode generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxPostcodeLength}.

What it means

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

Source

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

	arraySize?: number;
}> {
	static override readonly entityKind: string = 'GeneratePostcode';

	private state: {
		rng: prand.RandomGenerator;
		templates: string[];
	} | undefined;
	override uniqueVersionOfGen = GenerateUniquePostcode;

	override init({ count, seed }: { count: number; seed: number }) {
		super.init({ count, seed });

		const rng = prand.xoroshiro128plus(seed);
		const templates = ['#####', '#####-####'];

		const maxPostcodeLength = Math.max(...templates.map((template) => template.length));
		if (this.stringLength !== undefined && this.stringLength < maxPostcodeLength) {
			throw new Error(
				`You can't use postcode generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxPostcodeLength}.`,
			);
		}

		this.state = { rng, templates };
	}

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

		let idx: number, postcodeNumber: number;

		[idx, this.state.rng] = prand.uniformIntDistribution(0, this.state.templates.length - 1, this.state.rng);
		const template = this.state.templates[idx]!;

		const iterArray = [...template.matchAll(/#/g)];

View on GitHub (pinned to b7862528fd)

Solutions

  1. Increase the column's maximum string length to at least the maximum postcode length, or use a different generator.

When it happens

Trigger: Using the postcode generator on a column shorter than the longest postcode.

Common situations: Short varchar for postcodes; raise to maxPostcodeLength.


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