Answer the question
In order to leave comments, you need to log in
How to create composite primary key in sequelize nodejs?
const UserRole = sequelize.define(
'user_role',
{
user_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: User,
key: 'id'
}
},
role_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: Role,
key: 'id'
}
}
},
{
identifier: false,
timestamps: false,
indexes: [
{
primaryKey: true,
fields: ['user_id', 'role_id']
}
]
}
);
Answer the question
In order to leave comments, you need to log in
Try this https://github.com/sequelize/sequelize/issues/1485...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question