Sequelize bulkCreate() returns NULL value for primary key

前端 未结 7 1676
孤城傲影
孤城傲影 2020-12-15 04:46

I am writing rest using node, sequelize as ORM for mySQL. I am using bulkCreate function to create record in bulk. But in response it is returning null for

7条回答
  •  星月不相逢
    2020-12-15 04:58

    From the documentation: please notice that these may not completely represent the state of the rows in the DB. This is because MySQL and SQLite do not make it easy to obtain back automatically generated IDs and other default values in a way that can be mapped to multiple records. To obtain Instances for the newly created values, you will need to query for them again. http://docs.sequelizejs.com/class/lib/model.js~Model.html#static-method-bulkCreate

    But you can pass an option to make it return the id

    orm.models.category.bulkCreate(data, { returning: true })
    

提交回复
热议问题