Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
Sequelize cannot use build

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!