drizzle-team/drizzle-orm · error · Error

You can't use company name generator with a db column length

Error message

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}.

What it means

The GenerateCompanyName generator builds names from templates that combine last names and company-name suffixes (e.g. 'Smith Inc', 'Smith and Jones LLC'). It computes a minimum viable column width, maxCompanyNameLength = max(maxLastNameLength + maxCompanyNameSuffixLength + 1, 3*maxLastNameLength + 7), based on the longest entries in its built-in datasets. When the target DB column's varchar length is smaller than this minimum, the generator cannot guarantee its output will fit, so it refuses to initialize.

Source

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

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

		const rng = prand.xoroshiro128plus(seed);
		const templates = [
			{ template: '#', placeholdersCount: 1 },
			{ template: '# - #', placeholdersCount: 2 },
			{ template: '# and #', placeholdersCount: 2 },
			{ template: '#, # and #', placeholdersCount: 3 },
		];

		// 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}.`,
			);
		}

		this.state = { rng, templates };
	}

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

		let templateIdx, idx, lastName, companyNameSuffix, companyName;
		[templateIdx, this.state.rng] = prand.uniformIntDistribution(0, this.state.templates.length - 1, this.state.rng);
		const templateObj = this.state.templates[templateIdx]!;

		if (templateObj.template === '#') {
			[idx, this.state.rng] = prand.uniformIntDistribution(0, lastNames.length - 1, this.state.rng);

View on GitHub (pinned to b7862528fd)

Solutions

  1. Widen the column's varchar length to at least the maxCompanyNameLength value printed in the error message.
  2. If the column cannot be widened, override the generator in refinements with one that fits, e.g. GenerateString or GenerateCompanyName with a shorter custom source.
  3. Remove the explicit { length } from the column definition so the generator's stringLength is undefined and the check is skipped.

Example fix

// before
companyName: varchar('company_name', { length: 10 })
// after
companyName: varchar('company_name', { length: 50 })
Defensive patterns

Strategy: validation

Validate before calling

// Before assigning GenerateCompanyName, check the column width against the dataset-derived minimum.
// The exact floor depends on the bundled lastNames/companyNameSuffixes datasets.
// Safest approach: ensure the column length is comfortably large (>= 50).
const MIN_COMPANY_NAME_LENGTH = 50; // conservative lower bound; error message gives exact value
function columnFitsCompanyName(colLength: number | undefined): boolean {
  return colLength === undefined || colLength >= MIN_COMPANY_NAME_LENGTH;
}

Prevention

When it happens

Trigger: A varchar column with a short explicit length (e.g. varchar(10)) that drizzle-seed auto-assigns the company name generator to, or explicitly wiring GenerateCompanyName to a column whose { length } is below the computed minimum. The check runs in GenerateCompanyName.init() when this.stringLength (from col.typeParams.length) is defined and below the threshold.

Common situations: Legacy or compact schema with a narrow company_name column; column name pattern-matches the company-name heuristic but the length was chosen for abbreviations rather than full generated names.

Related errors


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