Reputation: 129
I tried to save the user information. But I'm getting below error.
Unhandled rejection SequelizeDatabaseError: Unknown column 'id' in 'field list' My Code is
var userObj = {userid: "aa", "emailid": "[email protected]", "user_type": "ENG"};
User.user
.build(userObj)
.save()
.then(anotherTask => {
console.log(anotherTask);
})
.catch(error => {
throw error;
});
I don't have id column in my table. How to exclude the id.
Upvotes: 1
Views: 3374
Reputation: 18647
In your question you mentioned How to exclude the id.
You can also remove the id
field completely by making the other field primaryKey: true
,
sequelize.define('user', {
userid: {
type: Sequelize.STRING,
allowNull: false,
primaryKey: true
},
emailid: Sequelize.STRING,
user_type: Sequelize.STRING
},{freezeTableName: true, tableName: 'user', id: false});
So, I added primaryKey: true
to userid
and now check, the id
will get disappered from the table.
Upvotes: 2
Reputation: 129
IF there is no Id in table make unique column as Id filed.
sequelize.define('user', {
'id': {
type: Sequelize.STRING,
field: 'userid',
allowNull: false,
primaryKey: true
},
userid: Sequelize.STRING,
emailid: Sequelize.STRING,
user_type: Sequelize.STRING
},{freezeTableName: true, tableName: 'user', id: false});
{id: "aa", "userid": "aa", "emailid": "[email protected]", "user_type": "ENG"};
Upvotes: -1