安装必要的库,这里使用的是mysql的迁移,所以除了db-migrate还需要db-migrate-mysql
npm install -g db-migrate
npm install db-migrate-mysql
2.写配置文件,比如在ocnfigs文件夹下面写一个文件:database_migrate.json
{
"dev": {
"host": "localhost",
"user": "your username",
"password" : "your password" ,
"database": "your db",
"driver": "mysql",
"multipleStatements": true
}
}
3.生成sql迁移文件
db-migrate create add-department --config configs/database_migrate.json --sql-file ```
(把add-department换成你想要的名字)
此时会在你的工程中生成几个文件
![image.png](http://upload-images.jianshu.io/upload_images/3523277-43772679ec89e886.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4.在 .....up.sql文件中写sql语句,比如你想增加