drizzle-team/drizzle-orm · error · Error

You have an empty array for "${name}" enum values

Error message

You have an empty array for "${name}" enum values

What it means

singlestoreEnum() throws when the values tuple passed to it is empty (values.length === 0). An enum column requires at least one value to generate valid DDL (ENUM('a',...)) and to satisfy its tuple type [string, ...string[]]; an empty array is treated as a schema definition error and rejected up front.

Source

Thrown at drizzle-orm/src/singlestore-core/columns/enum.ts:80

		return `enum(${this.enumValues!.map((value) => `'${value}'`).join(',')})`;
	}
}

export function singlestoreEnum<U extends string, T extends Readonly<[U, ...U[]]>>(
	values: T | Writable<T>,
): SingleStoreEnumColumnBuilderInitial<'', Writable<T>>;
export function singlestoreEnum<TName extends string, U extends string, T extends Readonly<[U, ...U[]]>>(
	name: TName,
	values: T | Writable<T>,
): SingleStoreEnumColumnBuilderInitial<TName, Writable<T>>;
export function singlestoreEnum(
	a?: string | readonly [string, ...string[]] | [string, ...string[]],
	b?: readonly [string, ...string[]] | [string, ...string[]],
): any {
	const { name, config: values } = getColumnNameAndConfig<readonly [string, ...string[]] | [string, ...string[]]>(a, b);

	if (values.length === 0) {
		throw new Error(`You have an empty array for "${name}" enum values`);
	}

	return new SingleStoreEnumColumnBuilder(name, values as any);
}

View on GitHub (pinned to b7862528fd)

Solutions

  1. Provide at least one enum value: singlestoreEnum('role', ['admin']).
  2. If values come from a dynamic source, guard with a non-empty check before defining the column and throw a clearer error or skip the table.
  3. Fix the data source so it always returns the expected enum members.

Example fix

// before (throws)
const roles: string[] = [];
const col = singlestoreEnum('role', roles as [string, ...string[]]);

// after
const roles = ['admin', 'user'] as const;
const col = singlestoreEnum('role', roles);
Defensive patterns

Strategy: validation

Validate before calling

function singlestoreEnumSafe(name: string, values: readonly string[]) {
  if (!Array.isArray(values) || values.length === 0) {
    throw new Error(`Enum "${name}" must have at least one value`);
  }
  return singlestoreEnum(name, values as [string, ...string[]]);
}

// Usage with a runtime guard before definition:
if (roles.length > 0) {
  const col = singlestoreEnumSafe('role', roles);
}

Type guard

function isNonEmptyStringArray(v: unknown): v is [string, ...string[]] {
  return Array.isArray(v) && v.every((x) => typeof x === 'string') && v.length > 0;
}

Try / catch

try {
  const col = singlestoreEnum('role', roles as [string, ...string[]]);
} catch (e) {
  if (e instanceof Error && /empty array for .* enum values/.test(e.message)) {
    // supply at least one value or skip defining the column
  } else throw e;
}

Prevention

When it happens

Trigger: Calling singlestoreEnum([]) or singlestoreEnum('name', []) or passing a variable that evaluates to an empty array, e.g. singlestoreEnum(roles) where roles is []. Also spreading a possibly-empty config-driven list: singlestoreEnum(...[...configValues]).

Common situations: Generating enum columns from a config/source list that is conditionally empty. Refactoring that leaves a placeholder singlestoreEnum([]) during scaffolding. Loading enum values from an external source that returns no entries.

Related errors


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