首页 > 解决方案 > RangeError [ERR_OUT_OF_RANGE]:“值”的值超出范围。它必须 >= 0 和 <= 4294967295。收到 9433906525

问题描述

对于我未插入的值,我收到此范围错误。

const createTransaction = async (yodleeAccountId, transaction) => {
  try {
    const savedRecord = await YodleeTransaction.create({
      YodleeAccountID: 373,
      YodleeID: 1887219837,
      Amount: 40518.32,
      AmountCurrency: 'USD',
      BaseType: 'CREDIT',
      Container: 'bank',
      PostDate: '2016-03-19',
      OriginalDescription: 'info about transaction',
      SimpleDescription: 'info',
      CategoryID: '2',
      Category: 'giving idk',
      CategoryType: 'the important type',
    })
    console.log('post create')
    return savedRecord
  } catch (error) {
    console.error('error finally caught', error)
    return error
  }
}

Yodlee交易模型:

module.exports = (sequelize, type) => {
  return sequelize.define(
    'YodleeTransaction',
    {
      ID: { type: type.BIGINT, primaryKey: true, autoIncrement: true },
      YodleeAccountID: { type: type.BIGINT, allowNull: false },
      YodleeID: { type: type.BIGINT, allowNull: false },
      Amount: { type: type.DECIMAL(12, 2), allowNull: false },
      AmountCurrency: { type: type.STRING(3) },
      BaseType: { type: type.STRING(25), allowNull: false },
      Container: { type: type.STRING(50) },
      PostDate: { type: type.DATE, allowNull: false },
      OriginalDescription: { type: type.STRING(800) },
      SimpleDescription: { type: type.STRING(500) },
      CategoryID: { type: type.INTEGER },
      Category: { type: type.STRING(50) },
      CategoryType: { type: type.STRING(50) },
    },
    { freezeTableName: true, tableName: 'YodleeTransaction' }
  )
}

错误:

RangeError [ERR_OUT_OF_RANGE]:“值”的值超出范围。它必须 >= 0 和 <= 4294967295。收到 9433906525

我知道 9433906525 以某种方式基于 ,Amount因为当我更改 时Amount,错误消息中的值会更改。例如,如果我将金额从 40518.32 更改为 8989.33,则收到的新值是 10728568304。新错误:

RangeError [ERR_OUT_OF_RANGE]:“值”的值超出范围。它必须 >= 0 和 <= 4294967295。收到 10728568304

标签: node.jssql-serverexpresssequelize.js

解决方案


这似乎是 Sequelize 中的一个错误。异步执行过多的插入或更新会导致这种情况发生。我不知道具体如何解决这个问题,但我可以告诉你如何解决它。

上述创建错误的解决方案是使用bulkCreate对象数组并将其传递给它。

如果您使用 t-sql 进行更新,则 Sequelize 不提供bulkUpdate方法。所以你应该手动写出里面的更新查询sequelize.query('UPDATE YodleeTransaction SET Amount=344.88')


推荐阅读