0

I am trying to add column 'player_id' to table in a migration, but getting error 'duplicate column name'.

My migration skeleton for this: -


module.exports = {
   up (queryInterface, Sequelize) {
    return queryInterface.sequelize.transaction(t => {
    return queryInterface.addColumn('Attackings', 'player_id',{
      type: Sequelize.DataTypes.INTEGER
    }, { transaction: t });
  });
  },

   down (queryInterface, Sequelize) {
    return queryInterface.sequelize.transaction(t => {
      return queryInterface.removeColumn('Attackings', 'player_id', { transaction: t });
    });
  }
};

My Attacking Model :-

'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class Attacking extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
    }
  }
  Attacking.init({
    player_name: DataTypes.STRING,
    club: DataTypes.STRING,
    position: DataTypes.STRING,
    assists: DataTypes.INTEGER,
    corner_taken: DataTypes.INTEGER,
    offsides: DataTypes.INTEGER,
    dribbles: DataTypes.INTEGER,
    match_played: DataTypes.INTEGER
  }, {
    sequelize,
    modelName: 'Attacking',
  });
  return Attacking;
};

As we can see column player_id doesn't already exists in table.

Error I am getting:- ERROR: Duplicate column name 'player_id'

3
  • You don't see it in the model but what about the table itself? Did you look at ut? Commented Sep 4, 2022 at 11:26
  • Yes i checked table also, there is no column named player_id. I have another table player, and i have created it using migration, but that was a separate migration, maybe because of that i am getting this problem, hence i named the column as 'playerid' now its working. Commented Sep 4, 2022 at 14:55
  • Have you tried this stackoverflow.com/questions/13333580/… Commented Sep 5, 2022 at 11:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.