{"id":"18bb001ddbab1917","repo":"sequelize/sequelize","slug":"cannot-use-offset-or-limit-without-a-model-or-orde","errorCode":null,"errorMessage":"Cannot use offset or limit without a model or order being set","messagePattern":"Cannot use offset or limit without a model or order being set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/abstract-dialect/query-generator.js","lineNumber":1381,"sourceCode":"      });\n\n      if (options.having) {\n        if (subQuery) {\n          subQueryItems.push(` HAVING ${options.having}`);\n        } else {\n          mainQueryItems.push(` HAVING ${options.having}`);\n        }\n      }\n    }\n\n    // Add ORDER to sub or main query\n    if (options.order) {\n      const orders = this.getQueryOrders(options, model, subQuery);\n      if (orders.mainQueryOrder.length > 0) {\n        mainQueryItems.push(` ORDER BY ${orders.mainQueryOrder.join(', ')}`);\n      } else if (!subQuery && (options.limit != null || options.offset)) {\n        if (!isModelStatic(model)) {\n          throw new Error('Cannot use offset or limit without a model or order being set');\n        }\n\n        // Always order by primary key if order is not specified and limit/offset is not null\n        const pks = [];\n        for (const pkAttrName of mainModelDefinition.primaryKeysAttributeNames) {\n          const attribute = mainModelAttributes.get(pkAttrName);\n          pks.push(attribute.columnName !== pkAttrName ? attribute.columnName : pkAttrName);\n        }\n\n        mainQueryItems.push(\n          ` ORDER BY ${pks.map(pk => `${mainTable.quotedAs}.${this.quoteIdentifier(pk)}`).join(', ')}`,\n        );\n      }\n\n      if (orders.subQueryOrder.length > 0) {\n        subQueryItems.push(` ORDER BY ${orders.subQueryOrder.join(', ')}`);\n      } else if (subQuery && (options.limit != null || options.offset)) {\n        if (!isModelStatic(model)) {","sourceCodeStart":1363,"sourceCodeEnd":1399,"githubUrl":"https://github.com/sequelize/sequelize/blob/7e1deec499d5afbb8d1877c2f4d545cead1214ec/packages/core/src/abstract-dialect/query-generator.js#L1363-L1399","documentation":"Error \"Cannot use offset or limit without a model or order being set\" thrown in sequelize/sequelize.","triggerScenarios":"Querying with offset or limit through a low-level API without a model context or order.","commonSituations":"Paginated queries built manually via queryInterface.","solutions":["Set the model (or an explicit order clause) when using offset/limit so the generated subquery is deterministic."],"exampleFix":"Model.findAll({ limit: 10, offset: 20, order: [['id', 'ASC']] });","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"7e1deec499d5afbb8d1877c2f4d545cead1214ec","analyzedAt":"2026-08-03T18:58:44.549Z","schemaVersion":2}