我已经完成了2个模型
带有字段的用户和订单
当我创建迁移文件时
续集迁移:创建 --name="create_users_and_orders"
我收到一个文件
新迁移创建于 20170319085303-create_users_and_orders.js
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
},
down: function (queryInterface, Sequelize) {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.dropTable('users');
*/
}
};
而且我必须自己创建字段,那为什么我们需要生成迁移?我可以自己创建一个简单的文件。
事实上,如果您希望立即生成迁移。您需要通过生成器创建模型。例如:
node_modules/.bin/sequelize model:create --name ModelName --attributes attribute1:data_type,attribute2:data_type然后将生成模型和迁移。
据我最终了解,迁移文件是空的,更准确地说是使用基本模板,自己编写所有“逻辑”。