0

我正在尝试使用 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在种子文件中,它们都运行成功,但是数据没有插入到表中,数据没有插入。我做错了什么吗?

4

2 回答 2

0

returnJavascript 会在悬空语句后自动添加分号。它没有到达bulkUpdate代码。

于 2019-06-19T03:08:03.247 回答
0

似乎有问题sequlizer,在return声明后它无法处理带有换行符的空格

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

    //new code
    return queryInterface.bulkUpdate('subject_tags', [
    //.........
于 2017-03-13T05:50:50.560 回答