#database #javascript #sequelize #npx

Sequelize CLI Commands

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


Comments

Feel Free to Comment

We'll never share your email with anyone else.
mohammed-samgan-khan

Hi, I am Samgan, I excel at solving complex problems involving logic and step by step breakdown of the problem. Besides, to develop complex algorithms, I specialise in problem framing, systems design, and product development strategy. Sometimes I also enjoy public speaking.  

I am also the creator of penit.ink, a site which provides young writers with a free hand place to show their creation to the world. Irrespective of the niche, if you write this place is defiantly for you.