繁体   English   中英

Sequelize播种器找不到正确的模型列名称

[英]Sequelize seeder doesn't find correct column name of model

我在一个使用sequelize作为ORM的nodeJS项目中,有一个模型“ Currency”,它是一个只有一列(名称)的表。 我已经为其创建了一个种子器,但是当我运行种子器时,它找不到该列的正确名称。 该模型是:

./app/models/Currency.js

'use strict';
module.exports = (sequelize, DataTypes) => {
    const Currency = sequelize.define('Currency', {
      name: { 
        type: DataTypes.STRING,
        allowNull: false,
        primaryKey: true
      }
    },
    {
      freezeTableName: true,
      tableName: 'currency',
      timestamps: false,
      id: false
    }
    );
    Currency.removeAttribute('id')
    return Currency
  }

种子文件./database/seeders/20190705045938-SeedCurrency.js

'use strict';

module.exports = {
  up: function(queryInterface) {
    return queryInterface.bulkUpdate('currency', [
        { name: 'USD' },
        { name: 'BRL' },
        { name: 'EUR' },
        { name: 'BTC' }
    ], {});
  },

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

当我运行node_modules/.bin/sequelize db:seed:all ,都会失败并显示以下错误:

== 20190705045938-SeedCurrency:正在迁移=======

错误:关系“货币”的列“ 0”不存在

配置此关系时我错过了什么? 提前致谢。

使用queryInterface.bulkInsert而不是bulkUpdate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM