This is my model class. It is located in a file called user.js:
const { Sequelize, Model, DataTypes} = require('sequelize');
class User extends Model{
static Init(sequelize){
var model = sequelize.define('user',{
id: {type:Sequelize.UUID, defaultValue: Sequelize.UUIDV4, primaryKey:true},
username: {type:DataTypes.STRING, allowNull:false},
password: {type:DataTypes.STRING, allowNull:false},
name: {type:DataTypes.STRING, allowNull:false},
});
return model;
}
GetName(){
return this.name;
}
};
module.exports = { User };
When I try to call the Sequelize build function from my app.js, I get this error:
C:\Users\testenv\Documents\Development\NodeJS\simple-express-project\node_modules\sequelize\lib\model.js:130 if (this.constructor.primaryKeyAttributes.length) { ^
TypeError: Cannot read properties of undefined (reading 'length') at User._initValues (C:\Users\testenv\Documents\Development\NodeJS\simple-express-project\node_modules\sequelize\lib\model.js:130:49) at new Model (C:\Users\testenv\Documents\Development\NodeJS\simple-express-project\node_modules\sequelize\lib\model.js:116:10) at new User (C:\Users\testenv\Documents\Development\NodeJS\simple-express-project\modals\user.js:4:1) at Function.build (C:\Users\testenv\Documents\Development\NodeJS\simple-express-project\node_modules\sequelize\lib\model.js:1311:12) at initialize (C:\Users\testenv\Documents\Development\NodeJS\simple-express-project\app.js:26:19) at processTicksAndRejections (node:internal/process/task_queues:96:5)
I have traced it to the app.js line 26 which is:
var nu = User.build({
username: "test"
})
I can't seem to access the properties of User in the build as well.