【发布时间】:2016-02-14 07:42:40
【问题描述】:
我正在尝试在创建数据库时保存批量数据。我的代码有以下问题:
- 如果我保留 models.sequelize.sync({force: true}).then(function(){ }); 则表示未创建表。
- 如果我保留 {force:false},那么在第一次部署中它会创建表,在第二次部署中它会将数据保存在数据库中。
模型/规范化.js
module.exports = function(sequelize, DataTypes) {
var Speclization = sequelize.define("Speclization",
{
speclizationname: DataTypes.STRING
}, {
tableName: 'speclization', // this will define the table's name
timestamps: false // this will deactivate the timestamp columns
}
);
Speclization.bulkCreate([
{speclizationname: 'Computer Science'}, // part of records argument
{speclizationname: 'Information Technology'},
{speclizationname: 'Electrical'},
{speclizationname: 'Other'},
{speclizationname: 'Mechninncal'},
{speclizationname: 'Electronics'}
], ['speclizationname'])
return Speclization;
};
我无法弄清楚如何在数据库中的应用程序部署中保存数据的正确方法
【问题讨论】:
标签: mysql node.js sequelize.js