npm i sequelize-cli -S
sequelize cmd依赖与sequelize
./node_modules/.bin/sequelize
./node_modules/.bin/sequelize init 初始化项目,生成一些文件 config 配置 models 模型 migrations 迁移文件 seeders 种子文件
./node_modules/.bin/sequelize db:create 创建数据库
./node_modules/.bin/sequelize model:create --name User --attributes username:STRING 创建模型user,属性username,在models目录下生成user.js,在migrations目录下生成20181109044804-create-user.js当前事件的js
./node_modules/.bin/sequelize db:migrate 迁移数据库
./node_modules/.bin/sequelize migration:create --name UserAddAge 创建迁移记录,在migrate目录下20181109074720-UserAddAge.js
之后,如果想在user表增加字段,移出20181109074720-UserAddAge.js,在db:migrate,在外面更改20181109074720-UserAddAge.js,更改完之后放回migrate目录下,之后再db:migrate
./node_modules/.bin/sequelize db:migrate:undo 回退最近一次操作
./node_modules/.bin/sequelize db:migrate:undo:all 删除所有迁移记录
种子文件记录记录迁移记录
./node_modules/.bin/sequelize seed:create --name userTest 创建种子文件
./node_modules/.bin/sequelize db:seed 创建已存在的种子文件
./node_modules/.bin/sequelize db:seed:undo:all 移除
./node_modules/.bin/sequelize init
./node_modules/.bin/sequelize model:create --name User --attributes username:STRING
./node_modules/.bin/sequelize model:create --name Message --attributes title:STRING
./node_modules/.bin/sequelize migration:create --name UserAddAge
创建迁移记录,在migrate目录下20181109074720-UserAddAge.js
之后,如果想在user表增加字段,移出20181109074720-UserAddAge.js,在db:migrate,在外面更改20181109074720-UserAddAge.js,更改完之后放回migrate目录下,之后再db:migrate
./node_modules/.bin/sequelize seed:create --name userTest 创建种子文件
config.json里配置"seederStorage": "sequelize",
"seederStoragePath": "userTestData.json",
"seederStorageTableName": "userTestData"
./node_modules/.bin/sequelize db:seed:all
./node_modules/.bin/sequelize db:seed:undo:all
重新添加删除后,再./node_modules/.bin/sequelize seed:create --name userTest 创建,再添加,就会在json文件里记录
而用sql记录则是"seederStorage": "sequelize",
"seederStoragePath": "userTestData.json",
"seederStorageTableName": "userTestData"
创建userTestData的数据库,重新添加,删除,再开始./node_modules/.bin/sequelize seed:create --name userTest 创建添加,就会开始在userTestData数据库中记录我们每次操作的增加记录等,每次修改什么内容,在js脚本中可以写