Fnr
Fnr

Reputation: 2274

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. 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:

'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:

'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:

== 20190705045938-SeedCurrency: migrating =======

ERROR: column "0" of relation "currency" does not exist

What did I miss when configuring this relation? Thanks in advance.

Upvotes: 0

Views: 395

Answers (1)

Anna Tolochko
Anna Tolochko

Reputation: 1855

Use queryInterface.bulkInsert instead of bulkUpdate.

Upvotes: 1

Related Questions