Sequelize/Postgres: NUMERIC scale 7 must be between 0 and precision 2

Viewed 66

Issue Can't seem to figure out how to resolve error when migrating decimal to Heroku.

In my sequelize, it is running fine but heroku is giving me this error for postgres:

migration

  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('Spots', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      address: {
        type: Sequelize.STRING(255),
        allowNull: false
      },
      city: {
        type: Sequelize.STRING(50),
        allowNull: false
      },
      state: {
        type: Sequelize.STRING(50),
        allowNull: false
      },
      country: {
        type: Sequelize.STRING(50),
        allowNull: false
      },
      lat: {
        type: Sequelize.DECIMAL(10, 7)
      },
      lng: {
        type: Sequelize.DECIMAL(10, 7)
      },
      name: {
        type: Sequelize.STRING(50)
      },
      description: {
        type: Sequelize.STRING(255)
      },
      price: {
        type: Sequelize.DECIMAL(4, 2)
      },
      avgStarRating: {
        type: Sequelize.DECIMAL(2, 1)
      },
      ownerId: {
        type: Sequelize.INTEGER
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE,
        defaultValue: Sequelize.literal("CURRENT_TIMESTAMP")
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE,
        defaultValue: Sequelize.literal("CURRENT_TIMESTAMP")
      }
    });
  },

Error

ERROR: NUMERIC scale 7 must be between 0 and precision 2

Sample output:

{
  "Spots": [
    {
      ...,
      "lat": 37.7645358,
      "lng": -122.4730327,
      ...
    }
  ]
}

Have tried changing all the DECIMAL to NUMERIC/FLOAT (just to try if it work) and still resulted in same error. What may I be doing wrong? Thank you!

1 Answers

For a numeric type, the first number is the total number of digits to be represented, including both sides of the decimal point. The second value is the number of digits to the right of the decimal point. Thus, (2, 7) does not make sense.

Related