Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda