sequelize table without column 'id'

Marc Rasmussen picture Marc Rasmussen · Mar 24, 2015 · Viewed 64k times · Source

i have the following sequelize definition of a table:

AcademyModule = sequelize.define('academy_module', {
        academy_id: DataTypes.INTEGER,
        module_id: DataTypes.INTEGER,
        module_module_type_id: DataTypes.INTEGER,
        sort_number: DataTypes.INTEGER,
        requirements_id: DataTypes.INTEGER
    }, {
        freezeTableName: true});

As you can see there is not an id column in this table. However when i try to insert it still tries the following sql:

 INSERT INTO `academy_module` (`id`,`academy_id`,`module_id`,`sort_number`) VALUES (DEFAULT,'3',5,1);

How can i disable the id function it clearly has?

Answer

Ben Fortune picture Ben Fortune · Mar 24, 2015

If you don't define a primaryKey then sequelize uses id by default.

If you want to set your own, just use primaryKey: true on your column.

AcademyModule = sequelize.define('academy_module', {
    academy_id: {
        type: DataTypes.INTEGER,
        primaryKey: true
    },
    module_id: DataTypes.INTEGER,
    module_module_type_id: DataTypes.INTEGER,
    sort_number: DataTypes.INTEGER,
    requirements_id: DataTypes.INTEGER
}, {
    freezeTableName: true
});