Answer the question
In order to leave comments, you need to log in
How to delete records from a table linked by key?
After deletion , the User,
linked user id
in Token
the table was deleted
const User = sequelize.define('user', {
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
email: { type: DataTypes.STRING, unique: true, allowNull: false },
password: { type: DataTypes.STRING, allowNull: false },
firstName: { type: DataTypes.STRING, allowNull: false },
lastName: { type: DataTypes.STRING, allowNull: false },
dateOfBirth: { type: DataTypes.DATEONLY, allowNull: false },
country: { type: DataTypes.STRING, allowNull: false },
gender: { type: DataTypes.STRING, allowNull: false },
subscribe: { type: DataTypes.BOOLEAN },
isActivated: { type: DataTypes.BOOLEAN, defaultValue: false },
activationLink: { type: DataTypes.STRING, allowNull: false },
role: { type: DataTypes.STRING, defaultValue: 'USER' },
})
const Token = sequelize.define('token', {
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
user: {
type: DataTypes.INTEGER,
references: { model: 'User', key: 'id' },
},
refreshToken: { type: DataTypes.STRING, allowNull: false },
})
Answer the question
In order to leave comments, you need to log in
...
user: {
type: DataTypes.INTEGER,
references: { model: 'User', key: 'id' }, onDelete: 'CASCADE',
},
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question