I'm trying to use.create in a model and the following exception is returned:
SequelizeDatabaseError: invalid input syntax for integer: \"[object Object]\"
All integer fields in PostgreSQL referring to the table are below:
CREATE TABLE public.cliente (
cd_clientefv bigserial NOT NULL,
cd_cliente int4 NULL,
cd_empresa int4 NOT NULL,
cd_cidadeibge int4 NOT NULL,
cd_pais int4 NOT NULL,
cd_regiaovendafv int8 NULL,
cd_vendedor int8 NOT NULL,
cd_estadoibge int4 NOT NULL,
);
My model:
const Cliente = database.define('cliente', {
cd_clientefv: {
type: Sequelize.BIGINT,
autoIncrement: true,
allowNull: false,
primaryKey: true
},
cd_cliente: {
type: Sequelize.INTEGER,
allowNull: false
},
cd_empresa: {
type: Sequelize.INTEGER,
allowNull: false
},
cd_cidadeibge: {
type: Sequelize.INTEGER,
allowNull: false
},
cd_pais: {
type: Sequelize.INTEGER,
allowNull: false
},
cd_regiaovendafv: {
type: Sequelize.BIGINT,
allowNull: true
},
cd_vendedor: {
type: Sequelize.BIGINT,
allowNull: false
},
cd_estadoibge: {
type: Sequelize.INTEGER,
allowNull: false
}
});
Body JSON:
[
{
"cd_cliente":8048,
"cd_cidadeibge":5210406,
"cd_pais":1058,
"cd_regiaovenda":14,
"cd_estadoibge":52,
"cd_empresa":5,
"cd_vendedor":25
}
]
Controller just try to:
await ClienteModel.create({
cd_cliente: cliente.cd_cliente,
cd_empresa: cd_empresa,
cd_cidadeibge: cliente.cd_cidadeibge,
cd_pais: cliente.cd_pais,
cd_regiaovendafv: cliente.cd_regiaovenda,
cd_vendedor: cdVendedor.cd_vendedor,
cd_estadoibge: cliente.cd_estadoibge
});
Apparently I have to pass an integer and an object is arriving, but that's not what happens?? When debugging what is actually present in each variable is an integer!
Note: there are several other tables that go through the same process, in none of them the same error is occurring; in 4 years of operation this exception never occurred, it started seemingly out of nowhere.
Please, is there something wrong or any additional information that could help with a possible resolution?
Based on your JSON body and Controller call examples:
[
{
"cd_cliente":8048,
"cd_cidadeibge":5210406,
"cd_pais":1058,
"cd_regiaovenda":14,
"cd_estadoibge":52,
"cd_empresa":5,
"cd_vendedor":25
}
]
await ClienteModel.create({
cd_cliente: cliente.cd_cliente,
cd_empresa: cd_empresa,
cd_cidadeibge: cliente.cd_cidadeibge,
cd_pais: cliente.cd_pais,
cd_regiaovendafv: cliente.cd_regiaovenda,
cd_vendedor: cdVendedor.cd_vendedor,
cd_estadoibge: cliente.cd_estadoibge
});
If I assume that
const cliente = {
"cd_cliente":8048,
"cd_cidadeibge":5210406,
"cd_pais":1058,
"cd_regiaovenda":14,
"cd_estadoibge":52,
"cd_empresa":5,
"cd_vendedor":25
}
The error may be caused by cd_empresa: cd_empresa
or cd_vendedor: cdVendedor.cd_vendedor
Did you check the type of those variables? cd_empresa
and cdVendedor.cd_vendedor
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.