Sequelize onDelete not working

走远了吗. 提交于 2019-11-29 08:17:05

I think you need to define it the other way around.

Contact.belongsTo(models.Users, {
    foreignKeyConstraint: true
    , onDelete: 'cascade'
})

Update association to User.hasMany(models.Contact, { onDelete: 'cascade', hooks: true }) to allow the hooks between associations to fire in order to enable the onDelete cascade. Adapted from the sequelize docs:

However, adding hooks: true explicitly tells Sequelize that optimization is not of your concern and will perform a SELECT on the associated objects and destroy each instance one by one in order to be able to call the hooks with the right parameters.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!