1. Install Sequelize CLI:
npm install --save-dev sequelize-cli
2. Create .sequelizerc File:
Create a file named .sequelizerc in the root of your project:
3. Generate a Migration:
Run the following command to generate a migration:
npx sequelize-cli migration:generate --name create-books
This will create a migration file in the src/database/migrations directory. Open the generated migration file (XXXXXXXXXXXXXX-create-books.js) and define your schema changes in the up and down functions.
4. Run the Migration:
Execute the following command to apply the changes defined in your migration file to the database:
npx sequelize-cli db:migrate
5. Generate a Seeder:
Run the following command to generate a seeder:
npx sequelize-cli seed:generate --name demo-books
This will create a seeder file in the src/database/seeders directory. Open the generated seeder file (XXXXXXXXXXXXXX-demo-books.js) and define the data you want to seed in the up function.
6. Run Seeders:
Execute the following command to run the seeders and populate your database with initial data:
npx sequelize-cli db:seed:all
Top comments (0)