{"id":"1cbeeacb3953e2bf","repo":"sequelize/sequelize","slug":"values-for-enum-haven-t-been-defined","errorCode":null,"errorMessage":"Values for ENUM haven't been defined.","messagePattern":"Values for ENUM haven't been defined\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/postgres/src/query-generator.js","lineNumber":241,"sourceCode":"    let type;\n    const arraySubtype =\n      attribute.type instanceof DataTypes.ARRAY ? attribute.type.options.type : null;\n\n    if (\n      attribute.type instanceof DataTypes.ENUM ||\n      (attribute.type instanceof DataTypes.ARRAY && arraySubtype instanceof DataTypes.ENUM)\n    ) {\n      const enumType = arraySubtype || attribute.type;\n      const values = enumType.options.values;\n\n      if (Array.isArray(values) && values.length > 0) {\n        type = `ENUM(${values.map(value => this.escape(value)).join(', ')})`;\n\n        if (attribute.type instanceof DataTypes.ARRAY) {\n          type += '[]';\n        }\n      } else {\n        throw new Error(\"Values for ENUM haven't been defined.\");\n      }\n    }\n\n    if (!type) {\n      type = attribute.type;\n    }\n\n    let sql = type.toString();\n\n    if (attribute.allowNull === false) {\n      sql += ' NOT NULL';\n    }\n\n    if (attribute.autoIncrement) {\n      if (attribute.autoIncrementIdentity) {\n        sql += ' GENERATED BY DEFAULT AS IDENTITY';\n      } else {\n        sql += ' SERIAL';","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/sequelize/sequelize/blob/7e1deec499d5afbb8d1877c2f4d545cead1214ec/packages/postgres/src/query-generator.js#L223-L259","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nstatus: { type: DataTypes.ENUM },\n\n// after\nstatus: { type: DataTypes.ENUM('draft', 'published', 'archived') },","handlingStrategy":"validation","validationCode":"function assertEnumHasValues(t) {\n  const values = t?.options?.values;\n  if (!(Array.isArray(values) && values.length > 0)) {\n    throw new Error('ENUM type must have a non-empty values array.');\n  }\n}","typeGuard":"function isEnumWithValues(t: unknown): boolean {\n  return (\n    !!t &&\n    typeof t === 'object' &&\n    Array.isArray((t as any).options?.values) &&\n    (t as any).options.values.length > 0\n  );\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["postgres","enum","data-types","model-definition"],"analyzedSha":"7e1deec499d5afbb8d1877c2f4d545cead1214ec","analyzedAt":"2026-08-03T18:58:44.549Z","schemaVersion":2}