【发布时间】:2016-03-31 18:59:54
【问题描述】:
在这里,我尝试在我的 sequelize db 中插入批量数据,但它会产生问题。 如何在angularjs中使用sequelize和postgres批量插入?
【问题讨论】:
-
我尝试了 sequelize cli,但缺少列出我的种子标志
标签: sequelize.js
在这里,我尝试在我的 sequelize db 中插入批量数据,但它会产生问题。 如何在angularjs中使用sequelize和postgres批量插入?
【问题讨论】:
标签: sequelize.js
首先使用sequelize seed:create --name nameofseed创建种子文件,它将在你的根目录中创建种子文件夹,在config.js的development:{seederStorage:'sequelize'}中添加seederStorage:'sequelize'
在这里给表名是offer,但在db中它是offers和json对象中的表字段。
创建播种机后,它需要分别migrate 和run。
这是运行种子的命令:sequelize db:seed:all,然后运行迁移命令:sequelize db:migrate 就是这样。
module.exports = {
up: function(queryInterface, Sequelize) {
queryInterface.bulkInsert('offers', [{
ban: [1],
sDate: '2016-03-31T08:00:10.354Z',
eDate: '2016-03-31T08:00:10.354Z',
isActive: true,
reminder: false,
sold: false,
couponFor: 'Coupon Code',
couponVal: 'Flat20%',
createdAt: '2016-03-31T08:00:10.354Z',
updatedAt: '2016-03-31T08:00:10.354Z'
},
{
ban: [1, 2],
sDate: '2016-03-31T08:00:10.354Z',
eDate: '2016-03-31T08:00:10.354Z',
isActive: true,
reminder: false,
sold: false,
couponFor: 'Coupon Code',
couponVal: 'Flat40%',
createdAt: '2016-03-31T08:00:10.354Z',
updatedAt: '2016-03-31T08:00:10.354Z'
},
{
ban: [1, 2],
sDate: '2016-03-31T08:00:10.354Z',
eDate: '2016-03-31T08:00:10.354Z',
isActive: true,
reminder: false,
sold: false,
couponFor: 'Coupon Code',
couponVal: 'Flat60%',
createdAt: '2016-03-31T08:00:10.354Z',
updatedAt: '2016-03-31T08:00:10.354Z'
},
{
ban: [1],
sDate: '2016-03-31T08:00:10.354Z',
eDate: '2016-03-31T08:00:10.354Z',
isActive: true,
reminder: false,
sold: false,
couponFor: 'Coupon Code',
couponVal: 'Flat100%',
createdAt: '2016-03-31T08:00:10.354Z',
updatedAt: '2016-03-31T08:00:10.354Z'
}], {});
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.bulkInsert('Person', [{
name: 'John Doe',
isBetaMember: false
}], {});
*/
},
down: function(queryInterface, Sequelize) {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.bulkDelete('Person', null, {});
*/
}
};
【讨论】:
development:{seederStorage:'sequelize'} 没有在 config.js 中设置也可以