在cockroachdb example后面使用sequelize orm for node.js构建应用程序时,我扩展了它以添加模型之间的关联。主键是INT,通过unique_rowid()自动递增。根据您的文档,这是您的实施SERIAL。在Node.js中使用SERIAL的外键违规
synching我的模型之后,我尝试使用下面的代码来创建记录:
models.sequelize.sync({ force: true })
.then(function() {
return models.Customer.create({
name: "Sample Customer"
})
})
.then(function (result) {
const id = parseInt(result.dataValues.id, 10)
return models.Order.bulkCreate([
{ subtotal: 100.00, customer_id: id },
{ subtotal: 200.00, customer_id: id }
])
})
当这个运行时,我得到“error: foreign key violation: value [255737842446434300] not found in [email protected] [id]
”
我意识到我parseInt不会出现有为了接受客户创建返回的字符串ID所需的精度,但我不知道如何完成此操作。