sequelize/sequelize · error · Error
Using LIMIT in bulkDeleteQuery requires specifying a model o
Error message
Using LIMIT in bulkDeleteQuery requires specifying a model or model definition.
What it means
Error "Using LIMIT in bulkDeleteQuery requires specifying a model or model definition." thrown in sequelize/sequelize.
Source
Thrown at packages/core/src/abstract-dialect/query-generator-typescript.ts:952
}
tableExistsQuery(tableName: TableOrModel): string {
const table = this.extractTableDetails(tableName);
return `SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME = ${this.escape(table.tableName)} AND TABLE_SCHEMA = ${this.escape(table.schema)}`;
}
bulkDeleteQuery(tableOrModel: TableOrModel, options: BulkDeleteQueryOptions): string {
const table = this.quoteTable(tableOrModel);
const modelDefinition = extractModelDefinition(tableOrModel);
const whereOptions = { ...options, model: modelDefinition };
const whereFragment = whereOptions.where
? this.whereQuery(whereOptions.where, whereOptions)
: '';
if (whereOptions.limit && !this.dialect.supports.delete.limit) {
if (!modelDefinition) {
throw new Error(
'Using LIMIT in bulkDeleteQuery requires specifying a model or model definition.',
);
}
const pks = join(
map(modelDefinition.primaryKeysAttributeNames.values(), attrName =>
this.quoteIdentifier(modelDefinition.getColumnName(attrName)),
),
', ',
);
const primaryKeys = modelDefinition.primaryKeysAttributeNames.size > 1 ? `(${pks})` : pks;
return joinSQLFragments([
`DELETE FROM ${table} WHERE ${primaryKeys} IN (`,
`SELECT ${pks} FROM ${table}`,
whereFragment,
`ORDER BY ${pks}`,View on GitHub (pinned to 7e1deec499)
Solutions
- Pass the model (or model definition) in options when calling bulkDelete with a limit, so Sequelize can generate the LIMIT subquery correctly.
- Remove the limit option if you intend to delete all matching rows.
Example fix
await MyModel.destroy({ where: { status: 'old' }, limit: 100 }); When it happens
Trigger: Calling QueryGenerator#bulkDeleteQuery (or Model.destroy) with a limit but without a model to derive the primary key from.
Common situations: Low-level queryInterface.bulkDelete calls that specify limit without a model.
AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03).
Data as JSON: /data/errors/296300d3cbb9fc2a.json.
Report an issue: GitHub.