#database #javascript #sequelize #npx

Sequelize CLI Commands

Table Of Content


  1. Create Model with Migration
  2. Create Migration
  3. Run Migration
  4. Adding Foreign Key to Migrations
  5. Create Seed
  6. Timestamp In Seed
  7. Run Seeder
  8. Run Single Seeder
  9. List all available CLI commands
  10. References

below is the list of commands for sequelize cli

Create Model with Migration

npx sequelize-cli model:generate --name User --attributes name:string,first_name:string

Create Migration

npx sequelize-cli migration:create --name modify_rates_add_weight

Run Migration

npx sequelize-cli db:migrate --env=development

Adding Foreign Key to Migrations

type: Sequelize.INTEGER,
references: {
    model: "vendors", // tables name not model name
    key: 'id'
}

Create Seed

npx sequelize-cli seed:generate --name shippers

Timestamp In Seed

created_at: new Date(),
updated_at: new Date()

Run Seeder

npx sequelize-cli db:seed:all

Run Single Seeder

npx sequelize-cli db:seed --seed 20220622131903-file_name.js

List all available CLI commands

npx sequelize-cli --list

References

  • npx sequelize-cli db:migrate | Run pending migrations
  • npx sequelize-cli db:migrate:schema:timestamps:add | Update migration table to have timestamps
  • npx sequelize-cli db:migrate:status | List the status of all migrations
  • npx sequelize-cli db:migrate:undo | Reverts a migration
  • npx sequelize-cli db:migrate:undo:all | Revert all migrations ran
  • npx sequelize-cli db:seed | Run specified seeder
  • npx sequelize-cli db:seed:undo | Deletes data from the database
  • npx sequelize-cli db:seed:all | Run every seeder
  • npx sequelize-cli db:seed:undo:all | Deletes data from the database
  • npx sequelize-cli db:create | Create database specified by configuration
  • npx sequelize-cli db:drop | Drop database specified by configuration
  • npx sequelize-cli init | Initializes project
  • npx sequelize-cli init:config | Initializes configuration
  • npx sequelize-cli init:migrations | Initializes migrations
  • npx sequelize-cli init:models | Initializes models
  • npx sequelize-cli init:seeders | Initializes seeders
  • npx sequelize-cli migration:generate | Generates a new migration file
  • npx sequelize-cli migration:create | Generates a new migration file
  • npx sequelize-cli model:generate | Generates a model and its migration
  • npx sequelize-cli model:create | Generates a model and its migration
  • npx sequelize-cli seed:generate | Generates a new seed file
  • npx sequelize-cli seed:create | Generates a new seed file

Most Viewed Posts


Must Read


January 28, 2022

#AppImage #linux

How to Add AppImage Application to Menu in Ubuntu (Linux)

AppImages are the most easiest to run compared.The challenging task is to make the AppImage accessible globally through he system like an installed application (in the menu)

Reading time: less than a minute
How to Add Laravel Pint to VS Code Formatter
June 24, 2022

#code-quality #vscode #laravel-pint #laravel

How to Add Laravel Pint to VS Code Formatter

I have been using the unsatisfactory formatters from a long time. All of them have one thing but lack other. Laravel Pint is one who has it all, combining it with vscode is like proving you laravel project a super power.

Reading time: 2 minutes
March 24, 2021

#express js #node #node js #sequelize #mysql

How to create model association in Sequelize - express JS / Node JS

In the very initial days of my work in Node JS if faced this issue. Though Sequelize provide a great ORM for MySQL but the association within the models is a bit tricky.

Reading time: 2 minutes
How to create a progressive web app (PWA) in laravel 5.* and above
July 07, 2019

#functionality #pwa #javascript #laravel

How to create a progressive web app (PWA) in laravel 5.* and above

The progressive web app is the new trend as well as the need for the present time. I hope before getting in the “HOW” part you know what is exactly a PWA

Reading time: 4 minutes
November 02, 2021

#laravel #tricks #eloquent

Approach to Handle Complex queries in laravel

I am familiar with the love of Eloquent among the laravel community but sometimes, sometimes its better to go for raw queries. Its saves you a lot of time and trouble.

Reading time: 1 minute
March 24, 2021

#express js #node #node js #sequelize #mysql

How to create model association in Sequelize - express JS / Node JS

In the very initial days of my work in Node JS if faced this issue. Though Sequelize provide a great ORM for MySQL but the association within the models is a bit tricky.

Reading time: 2 minutes
How to create a progressive web app (PWA) in laravel 5.* and above
July 07, 2019

#functionality #pwa #javascript #laravel

How to create a progressive web app (PWA) in laravel 5.* and above

The progressive web app is the new trend as well as the need for the present time. I hope before getting in the “HOW” part you know what is exactly a PWA

Reading time: 4 minutes
create-express-boilerplate to create new API projects in a secs
October 25, 2021

#express js #npm #deployment #api #node #node js #javascript #npx #boilerplate

create-express-boilerplate to create new API projects in a secs

Initiating a new project is as exciting as frustrating. Going through all the routine work just to get the basic engine started, yaa I know the pain.

Reading time: less than a minute
April 22, 2019

#javascript #validation #security

Client-side validation before uploading an excel file

Validation is one of the major parts of web development. But sometimes it can be a ball buster especially when it comes to validating file uploads.

Reading time: less than a minute
mohammed-samgan-khan

Hi, I am Samgan, I know the adds are bit annoying but i hope you understand. Talking about me, I excel at solving complex problems involving logic and step by step breakdown of the problem. Besides, to develop complex algorithms, I specialize in problem framing, systems design, and product development strategy. Sometimes I also enjoy public speaking.