Define a Database Model in Sequelize

Sequelize·2 min read·Jan 1, 2025

In Sequelize, a model is an abstraction that represents a table in the database and that tells several things about the entity it represents, such as its name, the name of its columns, their data types and constraints, and so on.

Defining a model

To create a new model, you can use the define() method of the database handler:

const { Sequelize } = require('sequelize');const database = new Sequelize(/* ... */);database.define(<model>, {  <column>: {    <property>: <value>,    ...  }}, <options>?);

Where:

  • <model> is the name of the database model.
  • <column> is the name of the column in the database.
  • <property> is either the type of the column or a constraint on the column.

Unlock the program 🚀

Pay once, own it forever.

€79

30-day money-back guarantee

  • 13 modules
  • 113 lessons with full-code examples
  • 29 projects with commented solutions
  • All future lesson and project updates
  • Lifetime access

By submitting this form, you agree to the Terms & Conditions and Privacy Policy.