Sequelize Cheatsheet

Command Line

Sequelize provides utilities for generating migrations, models, and seed files. They are exposed through the sequelize-cli command.

Init Project

$ npx sequelize-cli init

You must create a database user, and update the config/config.json file to match your database settings to complete the initialization process.

Create Database

$ npx sequelize-cli db:create

Generate a model and its migration

$ npx sequelize-cli model:generate --name <ModelName> --attributes <column1>:<type>,<column2>:<type>,...

Run pending migrations

$ npx sequelize-cli db:migrate

Rollback one migration

$ npx sequelize-cli db:migrate:undo

Rollback all migrations

Generate a new seed file

Run all pending seeds

Rollback one seed

Rollback all seeds

Migrations

Column Attribute Keywords

Model Associations

One to One between Student and Scholarship

student.js

scholarship.js

One to Many between Student and Class

student.js

class.js

Many to Many between Student and Lesson through StudentLessons table

student.js

lesson.js

Query Format

findOne

findAll

findByPk

Common Where Operators

Last updated

Was this helpful?