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 initYou 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:createGenerate a model and its migration
$ npx sequelize-cli model:generate --name <ModelName> --attributes <column1>:<type>,<column2>:<type>,...Run pending migrations
$ npx sequelize-cli db:migrateRollback one migration
$ npx sequelize-cli db:migrate:undoRollback 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?