Tôi đang viết phần còn lại bằng cách sử dụng nút, phần tiếp theo là ORM cho mySQL. Tôi đang sử dụng hàm bulkCreate để tạo bản ghi với số lượng lớn. Nhưng để trả lời, nó trả về null cho giá trị khóa chính.Sequelize bulkCreate() trả về giá trị NULL cho khóa chính
Mẫu
sequelize.define('category', {
cat_id:{
type:DataTypes.INTEGER,
field:'cat_id',
primaryKey: true,
autoIncrement: true,
unique:true
},
cat_name:{
type: DataTypes.STRING,
field: 'cat_name',
defaultValue:null
}
});
Bulk Tạo hoạt động:
var data = [
{
'cat_name':'fashion'
},
{
'cat_name':'food'
}
];
orm.models.category.bulkCreate(data)
.then(function(response){
res.json(response);
})
.catch(function(error){
res.json(error);
})
phản ứng:
[
{
"cat_id": null,
"cat_name": "fashion",
"created_at": "2016-01-29T07:39:50.000Z",
"updated_at": "2016-01-29T07:39:50.000Z"
},
{
"cat_id": null,
"cat_name": "food",
"created_at": "2016-01-29T07:39:50.000Z",
"updated_at": "2016-01-29T07:39:50.000Z"
}
]
Nhưng chỉ trong postgres và MSSQL –