[英]Sequelize seeder doesn't find correct column name of model
I have a model "Currency" which is a table with only one column (name), in a nodeJS project using sequelize as the ORM. 我在一个使用sequelize作为ORM的nodeJS项目中,有一个模型“ Currency”,它是一个只有一列(名称)的表。 I've created a seeder for it but when I run the seeder it doesn't find the correct name of the column.
我已经为其创建了一个种子器,但是当我运行种子器时,它找不到该列的正确名称。 The model is:
该模型是:
./app/models/Currency.js
: ./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
}
the seeder file, ./database/seeders/20190705045938-SeedCurrency.js
: 种子文件
./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, {});
}
};
When I run node_modules/.bin/sequelize db:seed:all
it fails with the error: 当我运行
node_modules/.bin/sequelize db:seed:all
,都会失败并显示以下错误:
== 20190705045938-SeedCurrency: migrating =======
== 20190705045938-SeedCurrency:正在迁移=======
ERROR: column "0" of relation "currency" does not exist
错误:关系“货币”的列“ 0”不存在
What did I miss when configuring this relation? 配置此关系时我错过了什么? Thanks in advance.
提前致谢。
使用queryInterface.bulkInsert
而不是bulkUpdate
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.