sequelize seed无法在SQLite中插入数据

时间:2017-02-19 10:31:15

标签: node.js sqlite sequelize.js seeding sequelize-cli

我正在尝试使用sequelize-cli命令插入虚拟数据

sequelize db:seed --seed seeders/20170212081140-subject_tags.js

这是我的配置文件

{
  "development": {
    "username": "root",
    "password": null,
    "database": "database_development",
    "host": "127.0.0.1",
    "dialect": "sqlite",
    "seederStorage": "sequelize",
    "storage": "./test"
  }
}

这里是我的播种文件

use strict';

module.exports = {
  up: function(queryInterface, Sequelize) {

    return 
      queryInterface.bulkUpdate('subject_tags', [

      {
        tag: 'agricultural-sciences',
        tag_description: '',
        subject_category: 'biological_&_medical_sciences',
        createdAt: new Date(),
        updatedAt: new Date()
      }, {
        tag: 'biochemistry',
        tag_description: '',
        subject_category: 'biological_&_medical_sciences',
        createdAt: new Date(),
        updatedAt: new Date()
      }, {
        tag: 'bioinformatics',
        tag_description: '',
        subject_category: 'biological_&_medical_sciences',
        createdAt: new Date(),
        updatedAt: new Date()
      }
    ] , {});
  },

  down: function(queryInterface, Sequelize) {
     return 
      queryInterface.bulkDelete('subject_tags', null, {});

  }
}; 

虽然我获得了状态

Using environment "development".
== 20170212081140-subject_tags: migrating =======
== 20170212081140-subject_tags: migrated (0.053s)

我在种子文件中尝试bulkCreatebulkInsert,所有这些都成功运行,但数据未插入表中 数据没有插入。我做错了吗?

2 个答案:

答案 0 :(得分:0)

sequlizer语句之后它似乎与return无关,它无法使用换行符处理空格

module.exports = {
  up: function(queryInterface, Sequelize) {
    //old code
    //return 
    //  queryInterface.bulkUpdate('subject_tags', [

    //new code
    return queryInterface.bulkUpdate('subject_tags', [
    //.........

答案 1 :(得分:0)

Javascript将在悬垂的return语句之后自动添加分号。 它没有达到bulkUpdate代码。