Skip to main content
Version: v7 - alpha

Advanced model definitions

Prevent creating a default PK attribute

By default, Sequelize automatically adds the primary key attribute id to every model when no primary key has been defined manually. To prevent this you can set the noPrimaryKey option to true when defining the model.

@Table({ noPrimaryKey: true })
export class User extends Model {}

If you want to prevent the addition of the default primary key for every model, you can also configure this option globally:

class User extends Model {}

const sequelize = new Sequelize({
define: {
noPrimaryKey: true,
models: [User],

Instances without primary keys can still be retrieved using Model.findOne and Model.findAll.


Some model methods require a primary key to be defined. For instance, Model.findByPk will throw an error if no primary key is defined.

If your model has no primary keys, you need to use the static equivalent of the following instance methods, and provide your own where parameter:

  • Model.update
  • instance.update: Model.update
  • instance.reload: Model.findOne
  • instance.destroy: Model.destroy
  • instance.restore: Model.restore
  • instance.decrement: Model.decrement
  • instance.increment: Model.increment

Caveat with minification

When defining a model, the name of the model will, by default, be the name of your class.

If you minify your code, the class name — and therefore its model name — may be changed by your minifier. This can be an issue, as many systems use your modelName, from sequelize.models to the name of the table associated to the model.

The solution to prevent this issue is to explicitly set the modelName option:

// by specifying 'modelName' explicitely, the name of this model can be safely minified.
@Table({ modelName: 'User' })
export class User extends Model {}