sequelize/sequelize · error · Error

Cannot use offset or limit without a model or order being se

Error message

Cannot use offset or limit without a model or order being set

What it means

Error "Cannot use offset or limit without a model or order being set" thrown in sequelize/sequelize.

Source

Thrown at packages/core/src/abstract-dialect/query-generator.js:1381

      });

      if (options.having) {
        if (subQuery) {
          subQueryItems.push(` HAVING ${options.having}`);
        } else {
          mainQueryItems.push(` HAVING ${options.having}`);
        }
      }
    }

    // Add ORDER to sub or main query
    if (options.order) {
      const orders = this.getQueryOrders(options, model, subQuery);
      if (orders.mainQueryOrder.length > 0) {
        mainQueryItems.push(` ORDER BY ${orders.mainQueryOrder.join(', ')}`);
      } else if (!subQuery && (options.limit != null || options.offset)) {
        if (!isModelStatic(model)) {
          throw new Error('Cannot use offset or limit without a model or order being set');
        }

        // Always order by primary key if order is not specified and limit/offset is not null
        const pks = [];
        for (const pkAttrName of mainModelDefinition.primaryKeysAttributeNames) {
          const attribute = mainModelAttributes.get(pkAttrName);
          pks.push(attribute.columnName !== pkAttrName ? attribute.columnName : pkAttrName);
        }

        mainQueryItems.push(
          ` ORDER BY ${pks.map(pk => `${mainTable.quotedAs}.${this.quoteIdentifier(pk)}`).join(', ')}`,
        );
      }

      if (orders.subQueryOrder.length > 0) {
        subQueryItems.push(` ORDER BY ${orders.subQueryOrder.join(', ')}`);
      } else if (subQuery && (options.limit != null || options.offset)) {
        if (!isModelStatic(model)) {

View on GitHub (pinned to 7e1deec499)

Solutions

  1. Set the model (or an explicit order clause) when using offset/limit so the generated subquery is deterministic.

Example fix

Model.findAll({ limit: 10, offset: 20, order: [['id', 'ASC']] });

When it happens

Trigger: Querying with offset or limit through a low-level API without a model context or order.

Common situations: Paginated queries built manually via queryInterface.


AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03). Data as JSON: /data/errors/18bb001ddbab1917.json. Report an issue: GitHub.