Sequelize.js:ER_ROW_IS_REFERENCED:无法删除或更新父行:外键约束失败 [英] Sequelize.js: ER_ROW_IS_REFERENCED: Cannot delete or update a parent row: a foreign key constraint fails

查看:57
本文介绍了Sequelize.js:ER_ROW_IS_REFERENCED:无法删除或更新父行:外键约束失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是:

DB.sequelize.query('SET FOREIGN_KEY_CHECKS = 0').complete(function(err) {
  if (err) {
    return done(err);
  }
  DB.sequelize.drop();
  return DB.sequelize.sync().complete(function(err) {
    if (err) {
      return done(err);
    }
  });
});

而且我有一些外键约束,但我认为 SET FOREIGN_KEY_CHECKS = 0 会忽略它并让我放弃.相反,我得到的错误是:ER_ROW_IS_REFERENCED:无法删除或更新父行:外键约束失败

and I have some foreign key constraints, but I thought that the SET FOREIGN_KEY_CHECKS = 0 would ignore that and let me drop. Instead, the error that I get is: ER_ROW_IS_REFERENCED: Cannot delete or update a parent row: a foreign key constraint fails

推荐答案

对于使用 sequelize 3.15.x 的任何人,他们都有 重构了他们的查询方法,以便在初始 SQL 语句之后的任何选项都包含在一个选项对象中.因此,答案将如下所示:

For anyone using sequelize 3.15.x they have refactored their query method so that any options after the initial SQL statement are contained in one options object. Thus the answer would look like this:

DB
    .sequelize
    .query('SET FOREIGN_KEY_CHECKS = 0', {raw: true})
    .then(function(results) {
        DB.sequelize.sync({force: true});
    });

这篇关于Sequelize.js:ER_ROW_IS_REFERENCED:无法删除或更新父行:外键约束失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆