A
A
Alexander2021-10-19 01:42:17
PostgreSQL
Alexander, 2021-10-19 01:42:17

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?

616df83757d1a942941779.png

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

1 answer(s)
A
antares4045, 2021-10-19
@axrising

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 question

Ask a Question

731 491 924 answers to any question