when i do a create like this
const user = User.create();
if i print user on console the ID it return undefined, the data was inserted on the database but the id return as undefined.
I am using sequelize v6 and mariadb
My User model:
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4
},
email_id: {
type: DataTypes.UUID,
defaultValue: null
},
auth_id: {
type: DataTypes.UUID,
defaultValue: null
}
}, {
tableName: 'user'
});
User.associate = function(models) {
User.hasOne(models.UserEmail, {foreignKey: 'email_id', as: 'email'}),
User.hasOne(models.UserAuth, {foreignKey: 'auth_id', as: 'auth'})
};
return User;
};
This is the console.log result
User {
dataValues: {
id: undefined,
updatedAt: 2021-11-10T11:37:08.793Z,
createdAt: 2021-11-10T11:37:08.793Z
},
_previousDataValues: {
id: undefined,
createdAt: 2021-11-10T11:37:08.793Z,
updatedAt: 2021-11-10T11:37:08.793Z
},
_changed: Set(0) {},
_options: {
isNewRecord: true,
_schema: null,
_schemaDelimiter: '',
attributes: undefined,
include: undefined,
raw: undefined,
silent: undefined
},
isNewRecord: false
}