sequelize/sequelize · error · Error
Values for ENUM haven't been defined.
Error message
Values for ENUM haven't been defined.
What it means
Thrown by attributeToSQL when a column is typed DataTypes.ENUM (or ARRAY(ENUM)) but the enum has no values defined (values is missing, not an array, or empty). Postgres requires an ENUM type to enumerate its allowed labels, so Sequelize cannot emit a valid column definition and aborts. This fires during sync/createTable/attributeToSQL.
Source
Thrown at packages/postgres/src/query-generator.js:241
let type;
const arraySubtype =
attribute.type instanceof DataTypes.ARRAY ? attribute.type.options.type : null;
if (
attribute.type instanceof DataTypes.ENUM ||
(attribute.type instanceof DataTypes.ARRAY && arraySubtype instanceof DataTypes.ENUM)
) {
const enumType = arraySubtype || attribute.type;
const values = enumType.options.values;
if (Array.isArray(values) && values.length > 0) {
type = `ENUM(${values.map(value => this.escape(value)).join(', ')})`;
if (attribute.type instanceof DataTypes.ARRAY) {
type += '[]';
}
} else {
throw new Error("Values for ENUM haven't been defined.");
}
}
if (!type) {
type = attribute.type;
}
let sql = type.toString();
if (attribute.allowNull === false) {
sql += ' NOT NULL';
}
if (attribute.autoIncrement) {
if (attribute.autoIncrementIdentity) {
sql += ' GENERATED BY DEFAULT AS IDENTITY';
} else {
sql += ' SERIAL';View on GitHub (pinned to 7e1deec499)
Solutions
- Provide a non-empty values array to the ENUM type: DataTypes.ENUM('a','b','c').
- If values are computed, ensure the array is populated before sync/migration runs.
- For dynamic enums, build the DataTypes.ENUM(...values) call from a validated non-empty source.
Example fix
// before
status: { type: DataTypes.ENUM },
// after
status: { type: DataTypes.ENUM('draft', 'published', 'archived') }, Defensive patterns
Strategy: validation
Validate before calling
function assertEnumHasValues(t) {
const values = t?.options?.values;
if (!(Array.isArray(values) && values.length > 0)) {
throw new Error('ENUM type must have a non-empty values array.');
}
} Type guard
function isEnumWithValues(t: unknown): boolean {
return (
!!t &&
typeof t === 'object' &&
Array.isArray((t as any).options?.values) &&
(t as any).options.values.length > 0
);
} Prevention
- Always declare ENUM with inline values: DataTypes.ENUM('a','b').
- If values come from a constant, assert the constant is non-empty at module load.
When it happens
Trigger: Defining a model attribute as DataTypes.ENUM with no values array, or DataTypes.ENUM([]). Also ARRAY(DataTypes.ENUM()) with no values. Occurs on Model.sync(), queryInterface.createTable, or migration that builds the column.
Common situations: Defining the enum dynamically and forgetting to pass values: [...]. Intending to add values later but syncing first. A refactor that moved the values list out and left the enum empty.
Related errors
- Expected type to be a string, a DataType class, or a DataTyp
- This DataType is already attached to ${printContext(this.usa
- DataTypes.RANGE is not supported in ${this._getDialect().nam
- DataTypes.ENUM cannot be used without specifying its possibl
- One of the possible values passed to DataTypes.ENUM (%O) is
AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03).
Data as JSON: /data/errors/1cbeeacb3953e2bf.json.
Report an issue: GitHub.