Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Sequelize:销毁/删除表中的所有记录_Mysql_Node.js_Sequelize.js - Fatal编程技术网

Mysql Sequelize:销毁/删除表中的所有记录

Mysql Sequelize:销毁/删除表中的所有记录,mysql,node.js,sequelize.js,Mysql,Node.js,Sequelize.js,我使用摩卡进行单元测试 当测试开始时,我想删除表中以前的所有记录 我所尝试的: db.User.destroy({ force: true }).then(() => { }).then(() => done()); db.User.destroy( {where: undefined}, {truncate: false} ).then(() => { return }).then(() => done()); db.User.dest

我使用摩卡进行单元测试

当测试开始时,我想删除表中以前的所有记录

我所尝试的:

db.User.destroy({ force: true }).then(() => {
}).then(() => done());


db.User.destroy(
    {where: undefined},
    {truncate: false}
).then(() => {
    return 
}).then(() => done());


db.User.destroy({}).then(() => {
    return db.User.bulkCreate(users)
}).then(() => done());
我不断得到以下错误:

 Error: Missing where or truncate attribute in the options parameter of model.destroy.
如何删除/销毁表中的所有记录?

您可以尝试使用

db.User.destroy({
  where: {},
  truncate: true
})

table.sync({force:true})为我工作

@Coxer不是。您将收到一个
未处理的PromisejectionWarning:错误:模型的选项参数中缺少where或truncate属性。销毁
错误您不需要where选项
db.User.destroy({truncate:true})
ok
truncate:true
如果有外键约束,可能无法工作。在这种情况下,您可以简单地删除该子句。这是一个更安全的解决方案。