개발모음집

Error: Include unexpected. Element has to be either a Model, an Association or an object 본문

Server/node.js

Error: Include unexpected. Element has to be either a Model, an Association or an object

void 2019. 12. 2. 10:00

Error: Include unexpected. Element has to be either a Model, an Association or an object 에러가 발생했다.

에러를 찾아보니 sequelize difine할 때, 

defaultScope: {
            where: {
                active: true
            }
        }
        

를 같이 써쭤야한다고 한다.

출처 : https://stackoverflow.com/questions/55896380/sequelize-js-include-unexpected-element-has-to-be-either-a-model-an-associati

 

Sequelize.js: Include unexpected. Element has to be either a Model, an Association or an object

I'm using Sequelize.js in my Node.js application and keep running into a very strange problem. Background: I have two models, Account and AccountCategory as follows. My API endpoint calls the route /

stackoverflow.com



module.exports = (sequelize, DataTypes) => {
    const User = sequelize.define('User', {
        email: {
            type: DataTypes.STRING(40), 
            allowNull: false, 
            unique: true, 
        },
        nickname: {
            type: DataTypes.STRING(20),
            allowNull: false,
        },
        password: {
            type: DataTypes.STRING(100),
            allowNull: false,
        },
    }, {
        charset: 'utf8',
        collate: 'utf8_general_ci',
        defaultScope: {
            where: {
                email: true // where절을 허용할 컬럼명을 써준다.
            }
        }
    });

    User.associate = (db) => {

    };
    return User;
};

 

where절 제대로 안쓰면 아래와 같이 컬럼이 없다고 나온다.

SequelizeDatabaseError: Unknown column 'User.active' in 'where clause'