'operator does not exist: character varying = integer in sequelize node js

I am trying to connect two tables with sequelize, but the primary key and foreign key have different data types, I am getting errors when I triggered the query. it is not possible to change the schema, it will affect the whole data. Can you provide some possible solutions to fix this error?



Solution 1:[1]

The only way to join them in findAll/findOne calls is to use the on option in the include option:

const items = Items.findAll({
  include: [{
    model: ChildItem,
    on: {
      // assuming that childId is an integer and parentId is a string
      childId: Sequelize.cast('parentId', 'integer')
    }
  }]
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anatoly