Linux command
sequelize 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Initialize sequelize
npx sequelize-cli init
Create model
npx sequelize-cli model:generate --name [User] --attributes [name:string,email:string]
Run migrations
npx sequelize-cli db:migrate
Undo last migration
npx sequelize-cli db:migrate:undo
Create seed
npx sequelize-cli seed:generate --name [demo-user]
Run seeds
npx sequelize-cli db:seed:all
Create migration
npx sequelize-cli migration:generate --name [add-column]
说明
sequelize-cli manages Sequelize ORM projects, providing scaffolding for models, migrations, and seed files. The init command creates the standard project structure with config, models, migrations, and seeders directories. Models define database table mappings with typed attributes, and the CLI generates both the model file and an initial migration. Migrations version the database schema using up and down functions, allowing incremental schema changes that can be applied or reverted. Seeds populate tables with initial or test data. The CLI supports PostgreSQL, MySQL, MariaDB, SQLite, and Microsoft SQL Server through Sequelize's database abstraction layer.
参数
- init
- Initialize project.
- model:generate
- Create model.
- db:migrate
- Run migrations.
- db:migrate:undo
- Revert migration.
- seed:generate
- Create seed file.
- db:seed:all
- Run all seeds.
- migration:generate
- Create migration.
- --name _NAME_
- Model/migration name.
- --attributes _ATTRS_
- Model attributes.
FAQ
What is the sequelize command used for?
sequelize-cli manages Sequelize ORM projects, providing scaffolding for models, migrations, and seed files. The init command creates the standard project structure with config, models, migrations, and seeders directories. Models define database table mappings with typed attributes, and the CLI generates both the model file and an initial migration. Migrations version the database schema using up and down functions, allowing incremental schema changes that can be applied or reverted. Seeds populate tables with initial or test data. The CLI supports PostgreSQL, MySQL, MariaDB, SQLite, and Microsoft SQL Server through Sequelize's database abstraction layer.
How do I run a basic sequelize example?
Run `npx sequelize-cli init` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does init do in sequelize?
Initialize project.