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
- Use `false` to disable the timestamp.
- Provide a non-empty string to rename it.
- 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
- Normalize env-driven config (e.g. process.env.CREATED_AT) to undefined when empty.
- Use false explicitly to disable a timestamp rather than an empty string.
- Add a config sanity check in test setup.
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
- Value for "${key}" option must be a string or a boolean, got
- Sequelize is trying to add the timestamp attribute ${NodeUti
- Sequelize is trying to add the timestamp attribute ${NodeUti
- Failed to resolve dialect from "${input}": the ${ref} of "${
- Failed to resolve dialect from "${input}": the ${ref} of "${
AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03).
Data as JSON: /data/errors/9765878c714bcf6a.json.
Report an issue: GitHub.