sequelize/sequelize · error · Error

The ${this.getDataTypeId()} DataType requires that the "prec

Error message

The ${this.getDataTypeId()} DataType requires that the "precision" option be specified if the "scale" option is specified.

What it means

BaseDecimalNumberDataType (data-types.ts:1020) enforces that precision and scale are either both set or both unset. The constructor throws when scale != null && precision == null because SQL DECIMAL(p,s) semantics are undefined when only scale is given (you cannot have digits after the decimal point without first defining total digits). This applies to DECIMAL and any decimal-based number type.

Source

Thrown at packages/core/src/abstract-dialect/data-types.ts:1031

    ...args:
      | []
      | [precision: number]
      | [precision: number, scale: number]
      | [options: DecimalNumberOptions]
  );

  constructor(precisionOrOptions?: number | DecimalNumberOptions, scale?: number) {
    if (isObject(precisionOrOptions)) {
      super(precisionOrOptions);
    } else {
      super({});

      this.options.precision = precisionOrOptions;
      this.options.scale = scale;
    }

    if (this.options.scale != null && this.options.precision == null) {
      throw new Error(
        `The ${this.getDataTypeId()} DataType requires that the "precision" option be specified if the "scale" option is specified.`,
      );
    }

    if (this.options.scale == null && this.options.precision != null) {
      throw new Error(
        `The ${this.getDataTypeId()} DataType requires that the "scale" option be specified if the "precision" option is specified.`,
      );
    }
  }

  validate(value: any): asserts value is AcceptedNumber {
    if (Number.isNaN(value)) {
      const typeId = this.getDataTypeId();
      const dialect = this._getDialect();

      // @ts-expect-error -- 'typeId' is string, but only some dataTypes are objects
      if (dialect.supports.dataTypes[typeId]?.NaN) {

View on GitHub (pinned to 7e1deec499)

Solutions

  1. Provide both: DataTypes.DECIMAL(10, 2) or { precision: 10, scale: 2 }.
  2. Provide neither to get an unconstrained DECIMAL (only where the dialect supports it, see error 24).
  3. Re-check that your options object includes both precision and scale keys.

Example fix

// before
amount: { type: DataTypes.DECIMAL({ scale: 2 }) }

// after
amount: { type: DataTypes.DECIMAL({ precision: 10, scale: 2 }) }
Defensive patterns

Strategy: validation

Validate before calling

function decimalType(p, s) {
  if ((s != null) && (p == null)) throw new Error('precision required when scale is set');
  return DataTypes.DECIMAL(p, s);
}

Type guard

function hasBalancedPrecisionScale(o = {}) {
  const { precision, scale } = o;
  return (precision == null) === (scale == null);
}

Prevention

When it happens

Trigger: Calling DataTypes.DECIMAL(undefined, 2), new DECIMAL({ scale: 4 }), or BaseDecimalNumberDataType with only the scale option set.

Common situations: Mistakenly thinking scale alone means '2 decimal places'; migrating a schema doc that only listed decimal places; refactoring options objects and dropping the precision field.

Related errors


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