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
Thrown by the mysqlEnum factory (line 120) in string-union mode when the provided values array is empty. MySQL ENUM requires at least one value; Drizzle enforces this at schema definition time to avoid generating invalid `enum()` DDL.
Source
Thrown at drizzle-orm/src/mysql-core/columns/enum.ts:120
): MySqlEnumColumnBuilderInitial<TName, Writable<T>>;
export function mysqlEnum<E extends Record<string, string>>(
enumObj: NonArray<E>,
): MySqlEnumObjectColumnBuilderInitial<'', E>;
export function mysqlEnum<TName extends string, E extends Record<string, string>>(
name: TName,
values: NonArray<E>,
): MySqlEnumObjectColumnBuilderInitial<TName, E>;
export function mysqlEnum(
a?: string | readonly [string, ...string[]] | [string, ...string[]] | Record<string, string>,
b?: readonly [string, ...string[]] | [string, ...string[]] | Record<string, string>,
): any {
// if name + array or just array - it means we have string union passed
if (typeof a === 'string' && Array.isArray(b) || Array.isArray(a)) {
const name = typeof a === 'string' && a.length > 0 ? a : '';
const values = (typeof a === 'string' ? b : a) ?? [];
if (values.length === 0) {
throw new Error(`You have an empty array for "${name}" enum values`);
}
return new MySqlEnumColumnBuilder(name, values as any);
}
if (typeof a === 'string' && typeof b === 'object' || typeof a === 'object') {
const name = typeof a === 'object' ? '' : a;
const values = typeof a === 'object' ? Object.values(a) : typeof b === 'object' ? Object.values(b) : [];
if (values.length === 0) {
throw new Error(`You have an empty array for "${name}" enum values`);
}
return new MySqlEnumObjectColumnBuilder(name, values as any);
}
}
View on GitHub (pinned to b7862528fd)
Solutions
- Provide at least one enum value: mysqlEnum('status', ['active', 'inactive']).
- If values come from a dynamic source, validate non-empty before passing to mysqlEnum and fall back to a default value.
- Reconsider whether the column should be an enum at all if the value set is truly empty/variable.
Example fix
// before
const statuses: string[] = loadFromConfig(); // []
const t = mysqlTable('t', {
status: mysqlEnum('status', statuses as [string, ...string[]]),
});
// after - guard with a default
const statuses = loadFromConfig();
if (statuses.length === 0) statuses.push('unknown');
const t = mysqlTable('t', {
status: mysqlEnum('status', statuses as [string, ...string[]]),
}); Defensive patterns
Strategy: validation
Validate before calling
if (!Array.isArray(values) || values.length === 0) {
throw new Error('mysqlEnum requires a non-empty values array');
}
// values is non-empty here
mysqlEnum('status', values as [string, ...string[]]); Type guard
function isNonEmptyStringArray(v: unknown): v is [string, ...string[]] {
return Array.isArray(v) && v.every((x) => typeof x === 'string') && v.length > 0;
} Prevention
- Always supply at least one enum value in the schema.
- Validate dynamic enum sources for non-emptiness at module load.
- Reconsider enum vs free-text if the value set is variable.
When it happens
Trigger: Calling mysqlEnum('columnName', []) or mysqlEnum([]) with an empty array (or a readonly tuple typed as empty). The check `values.length === 0` fires before constructing MySqlEnumColumnBuilder.
Common situations: Enum values loaded from a config/env that resolved to an empty array; refactoring that temporarily empties an enum; dynamic enum construction where the source list is empty at module load.
Related errors
- You have an empty array for "${name}" enum values
- Your "${f.path.join('->')}" field references a column "${tab
- Cannot pass undefined values to any set operator
- values() must be called with at least one value
- Insert select error: selected fields are not the same or are
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/762e9f4da87bab29.json.
Report an issue: GitHub.