sequelize/sequelize · error · Error

Value for "${key}" option cannot be an empty string

Error message

Value for "${key}" option cannot be an empty string

What it means

At model-definition.ts:304-306 the constructor rejects an empty string for createdAt/updatedAt/deletedAt, because `''` is neither a valid attribute name nor the `false` value used to disable a timestamp. An empty string would produce an attribute with no usable name.

Source

Thrown at packages/core/src/model-definition.ts:305

      rawAttributes[attributeName] = rawAttribute;

      if (rawAttribute.field) {
        fieldToColumn();
      }
    }

    // setup names of timestamp attributes
    if (this.options.timestamps) {
      for (const key of ['createdAt', 'updatedAt', 'deletedAt'] as const) {
        if (!['undefined', 'string', 'boolean'].includes(typeof this.options[key])) {
          throw new Error(
            `Value for "${key}" option must be a string or a boolean, got ${typeof this.options[key]}`,
          );
        }

        if (this.options[key] === '') {
          throw new Error(`Value for "${key}" option cannot be an empty string`);
        }
      }

      if (this.options.createdAt !== false) {
        this.timestampAttributeNames.createdAt =
          typeof this.options.createdAt === 'string' ? this.options.createdAt : 'createdAt';

        this.#readOnlyAttributeNames.add(this.timestampAttributeNames.createdAt);
      }

      if (this.options.updatedAt !== false) {
        this.timestampAttributeNames.updatedAt =
          typeof this.options.updatedAt === 'string' ? this.options.updatedAt : 'updatedAt';
        this.#readOnlyAttributeNames.add(this.timestampAttributeNames.updatedAt);
      }

      if (this.options.paranoid && this.options.deletedAt !== false) {
        this.timestampAttributeNames.deletedAt =

View on GitHub (pinned to 7e1deec499)

Solutions

  1. Use `false` to disable the timestamp.
  2. Provide a non-empty string to rename it.
  3. Normalize empty config values to `undefined` so Sequelize uses the default.

Example fix

// before
User.init(attrs, { sequelize, timestamps: true, createdAt: process.env.CREATED_AT || '' });

// after
User.init(attrs, { sequelize, timestamps: true, createdAt: process.env.CREATED_AT || undefined });
Defensive patterns

Strategy: validation

Validate before calling

function assertNoEmptyTimestampStrings(opts) {
  if (!opts.timestamps) return;
  for (const key of ['createdAt', 'updatedAt', 'deletedAt']) {
    if (opts[key] === '') throw new Error(`${key} cannot be an empty string; use false to disable.`);
  }
}
assertNoEmptyTimestampStrings(modelOptions);

Type guard

function isNonEmptyStringOrFalse(v) {
  return v === undefined || v === false || (typeof v === 'string' && v.length > 0);
}

Prevention

When it happens

Trigger: Passing `{ timestamps: true, createdAt: '' }` (or updatedAt/deletedAt) — often from a config variable that resolved to an empty string.

Common situations: Environment-driven config (`process.env.CREATED_AT`) that is unset and defaults to `''`; conditional logic that builds the option name but yields empty.

Related errors


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