sequelize/sequelize · error · Error
Migration ${inspect(migrationName)} has an invalid "down" ex
Error message
Migration ${inspect(migrationName)} has an invalid "down" export: It must be a function, but it is ${inspect(down)} What it means
createJsMigration located a `down` export but `isFunction(down)` is false. Since `down` is invoked as a function to revert the migration, a non-callable value is rejected.
Source
Thrown at packages/cli/src/api/get-umzug.ts:162
);
}
const sequelize = migrationParams.context.sequelize;
await up(sequelize.queryInterface, sequelize, migrationParams);
},
down: async migrationParams => {
const migration = await import(pathToFileURL(migrationPath).href);
const down = migration.down ?? migration.default?.down;
if (!down) {
throw new Error(
`Migration ${inspect(migrationName)} is missing the "down" export, so cannot be reverted.`,
);
}
if (!isFunction(down)) {
throw new Error(
`Migration ${inspect(migrationName)} has an invalid "down" export: It must be a function, but it is ${inspect(down)}`,
);
}
const sequelize = migrationParams.context.sequelize;
await down(sequelize.queryInterface, sequelize, migrationParams);
},
};
}
View on GitHub (pinned to 7e1deec499)
Solutions
- Make `down` a function: `export async function down(queryInterface) { ... }`.
- If irreversibility is intended, omit `down` entirely (you will get error [7] on undo instead) and simply never undo it.
Example fix
// before
export const down = null;
// after
export async function down(queryInterface) { await queryInterface.dropTable('users'); } Defensive patterns
Strategy: type-guard
Validate before calling
function assertDownIsFunction(mod: any, file: string) {
const down = mod.down ?? mod.default?.down;
if (typeof down !== 'function') {
throw new Error(`'down' in ${file} must be a function, got ${typeof down}`);
}
} Type guard
function isMigrationDown(mod: any): mod is { down: (...a: any[]) => any } {
return typeof mod?.down === 'function' || typeof mod?.default?.down === 'function';
} Prevention
- Never assign non-function values to `down`; if irreversible, omit `down` and avoid undoing it.
- Run a CI check asserting `down` is a function for every migration file.
When it happens
Trigger: Exporting `down` as a non-function — an object, string, or constant — in a JS migration that is then reverted.
Common situations: Placeholder `export const down = null`/`false`; copying a config object into `down`; refactor leftover.
Related errors
- Migration ${inspect(migrationName)} has an invalid "up" expo
- Migration ${inspect(migrationName)} is missing the "down" ex
- Migration ${inspect(migrationName)} does not have a down mig
- Migration ${inspect(migrationName)} is missing the "up" expo
- Invalid options: "to" and "step" cannot both be specified.
AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03).
Data as JSON: /data/errors/201f22fca739ab70.json.
Report an issue: GitHub.