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

  1. Provide a non-empty values array to the ENUM type: DataTypes.ENUM('a','b','c').
  2. If values are computed, ensure the array is populated before sync/migration runs.
  3. 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

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


AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03). Data as JSON: /data/errors/1cbeeacb3953e2bf.json. Report an issue: GitHub.