{"id":"296300d3cbb9fc2a","repo":"sequelize/sequelize","slug":"using-limit-in-bulkdeletequery-requires-specifying","errorCode":null,"errorMessage":"Using LIMIT in bulkDeleteQuery requires specifying a model or model definition.","messagePattern":"Using LIMIT in bulkDeleteQuery requires specifying a model or model definition\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/abstract-dialect/query-generator-typescript.ts","lineNumber":952,"sourceCode":"  }\n\n  tableExistsQuery(tableName: TableOrModel): string {\n    const table = this.extractTableDetails(tableName);\n\n    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)}`;\n  }\n\n  bulkDeleteQuery(tableOrModel: TableOrModel, options: BulkDeleteQueryOptions): string {\n    const table = this.quoteTable(tableOrModel);\n    const modelDefinition = extractModelDefinition(tableOrModel);\n    const whereOptions = { ...options, model: modelDefinition };\n    const whereFragment = whereOptions.where\n      ? this.whereQuery(whereOptions.where, whereOptions)\n      : '';\n\n    if (whereOptions.limit && !this.dialect.supports.delete.limit) {\n      if (!modelDefinition) {\n        throw new Error(\n          'Using LIMIT in bulkDeleteQuery requires specifying a model or model definition.',\n        );\n      }\n\n      const pks = join(\n        map(modelDefinition.primaryKeysAttributeNames.values(), attrName =>\n          this.quoteIdentifier(modelDefinition.getColumnName(attrName)),\n        ),\n        ', ',\n      );\n\n      const primaryKeys = modelDefinition.primaryKeysAttributeNames.size > 1 ? `(${pks})` : pks;\n\n      return joinSQLFragments([\n        `DELETE FROM ${table} WHERE ${primaryKeys} IN (`,\n        `SELECT ${pks} FROM ${table}`,\n        whereFragment,\n        `ORDER BY ${pks}`,","sourceCodeStart":934,"sourceCodeEnd":970,"githubUrl":"https://github.com/sequelize/sequelize/blob/7e1deec499d5afbb8d1877c2f4d545cead1214ec/packages/core/src/abstract-dialect/query-generator-typescript.ts#L934-L970","documentation":"Error \"Using LIMIT in bulkDeleteQuery requires specifying a model or model definition.\" thrown in sequelize/sequelize.","triggerScenarios":"Calling QueryGenerator#bulkDeleteQuery (or Model.destroy) with a limit but without a model to derive the primary key from.","commonSituations":"Low-level queryInterface.bulkDelete calls that specify limit without a model.","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."],"exampleFix":"await MyModel.destroy({ where: { status: 'old' }, limit: 100 });","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"7e1deec499d5afbb8d1877c2f4d545cead1214ec","analyzedAt":"2026-08-03T18:58:44.549Z","schemaVersion":2}