Answer the question
In order to leave comments, you need to log in
Is it correct to use string for primary key sequelize?
Is it correct to use string for primary key sequelize?
Faced a problem when you need to display the category as a string to show in ui, but got the id as a number,
now I changed it to a string and I'm not sure if this is the right solution?
const Category = sequelize.define('category', {
// id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
category: { type: DataTypes.STRING, primaryKey: true, unique: true, allowNull: false },
})
Answer the question
In order to leave comments, you need to log in
Purely theoretically, this is not very good: it is much less convenient to make indexes on the lines of the base than on uuids or numbers. But until you are designing a highly loaded system with millions of inserts per minute, make an architecture that is comfortable for you to use and don't listen to Nazi code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question