最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何在连续迁移中使用insert()?

运维笔记admin10浏览0评论

如何在连续迁移中使用insert()?

如何在连续迁移中使用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定义的模型实例。

发布评论

评论列表(0)

  1. 暂无评论