gpt4 book ai didi

mysql - 如何使用sequelize mysql在Nodejs中保存数据时排除Id

转载 作者:行者123 更新时间:2023-11-29 10:18:17 26 4
gpt4 key购买 nike

我尝试保存用户信息。但我遇到了以下错误。

Unhandled rejection SequelizeDatabaseError: Unknown column 'id' in 'field list' My Code is

var userObj = {userid: "aa", "emailid": "aa@aa.com", "user_type": "ENG"};
User.user
.build(userObj)
.save()
.then(anotherTask => {
console.log(anotherTask);
})
.catch(error => {
throw error;
});

我的表中没有 id 列。如何排除 id。

enter image description here

最佳答案

在您的问题中,您提到如何排除 ID。

您还可以通过将另一个字段设置为 primaryKey: true 来完全删除 id 字段,

sequelize.define('user', {
userid: {
type: Sequelize.STRING,
allowNull: false,
primaryKey: true
},
emailid: Sequelize.STRING,
user_type: Sequelize.STRING
},{freezeTableName: true, tableName: 'user', id: false});

因此,我将 primaryKey: true 添加到 userid 中,现在检查 id 将从表中消失。

关于mysql - 如何使用sequelize mysql在Nodejs中保存数据时排除Id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49775973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com