如何在连续迁移中使用insert()?
我想在Sequelize迁移中仅使用insert()
创建一行。我看过bulkInsert()
的示例,但不想使用批量。我们只有此功能才能创建一行:
insert(instance, tableName, values, options)
但是我不明白param中的实例是什么?我正在使用bulkInsert
,因为它不询问实例参数。如果您可以在下面编写的代码中添加插入内容,那就太好了。迁移库:.js
//Code for insertion using bulkInsert
module.exports = {
up: queryInterface => {
queryInterface.describeTable("Platforms").then(attributes => {
return queryInterface.bulkInsert("Platforms", [
{
id: 6,
display_name: "Booking",
code: "booking"
}
]);
});
},
down: queryInterface => {
return queryInterface.bulkDelete("Platforms", {
id: 6
});
}
};
回答如下: import Platform from '../models/Platform';
module.exports = {
up: queryInterface => {
queryInterface.describeTable("Platforms").then(attributes => {
return queryInterface.insert(Platform, "Platforms", [
{
id: 6,
display_name: "Booking",
code: "booking"
}
]);
});
},
down: queryInterface => {
return queryInterface.bulkDelete("Platforms", {
id: 6
});
}
};
这里的实例是您使用sequilize定义的模型实例。