Sometimes, we want to add Sequelize table without column ‘id’ with JavaScript.
In this article, we’ll look at how to add Sequelize table without column ‘id’ with JavaScript.
How to add Sequelize table without column ‘id’ with JavaScript?
To add Sequelize table without column ‘id’ with JavaScript, we define a table with our own primary key column.
For instance, we write
const 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,
}
);
to call sequelize.define
with the table name and an object with the column names and their types.
We add the academy_id
primary key column so the id
column won’t be added automatically.
Conclusion
To add Sequelize table without column ‘id’ with JavaScript, we define a table with our own primary key column.