cli icon indicating copy to clipboard operation
cli copied to clipboard

Duplicate id column on model:generate

Open lacivert opened this issue 5 years ago • 2 comments

What you are doing?

npx sequelize-cli model:generate --name Company --attributes name:string,id:number

What do you expect to happen?

  • Either give error because id column already getting defined via this command;
  • Or create only only one id column without any default assumptions because I give a column name as 'id'

What is actually happening?

This is the generated model which has two id columns (unacceptable)

'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('Companies', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      name: {
        type: Sequelize.STRING
      },
      id: {
        type: Sequelize.NUMBER
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable('Companies');
  }
};

Dialect: postgres (but probably this is for all) Database version: Not important Sequelize CLI version: 5.5.1 Sequelize version: 5.21.5

lacivert avatar Feb 27 '20 01:02 lacivert

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 21 '20 18:06 stale[bot]

Any news about this?

lacivert avatar Jun 22 '20 08:06 lacivert