I get this weird error when I was trying to sync my database:
Unhandled rejection Error: Cyclic dependency found. roles is dependent of itself.
Dependency chain: roles -> users => roles
I have this following junction table model called Permission
const Permission = db.define('permission', {
id: {
type: type.INTEGER,
primaryKey: true,
autoIncrement: true
},
role_id: {
type: type.INTEGER,
references: {
model: 'roles',
key: 'id',
}
},
resource_id: {
type: type.INTEGER,
references: {
model: 'resources',
key: 'id',
}
},
});
Why does this error happen? And how can I fix it? In my User model, User has one Role :
const User = db.define('user', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
role_id : {
type: Sequelize.INTEGER,
references: {
model: 'roles',
key: 'id',
}
}
});
User.hasOne(Role)
Edit : Here's my Role model:
const Role = db.define('role', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: Sequelize.STRING,
})
module.exports = Role