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'