我正在尝试使用sequelize和sequelize-cli通过迁移机制创建数据库模式更改(MSSQL)。但是没有发生任何事情-它看起来在迁移文件夹中找不到任何迁移文件。
我在一个新文件夹中执行了以下操作来创建一个测试项目:
npm init
[ added relevant packages: sequelize, sequelize-cli, tedious ]
sequelize init
[ here I added the connection information, all to a blank database on Azure SQL ]
sequelize init:models
sequelize init:migrations
sequelize migration:create我在创建的迁移文件中添加了以下内容:
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
},
down: function (queryInterface, Sequelize) {
return queryInterface.dropTable('users');
}
};这基本上只是根据最后的sequelize命令创建的模板。
现在,我希望在运行迁移命令时创建一个新表:
sequelize db:migrate但我得到的是这样的:
Sequelize [Node: 0.12.2, CLI: 1.7.4, ORM: 3.5.1]
Loaded configuration file "config/config.json".
Using environment "development".
Using gulpfile /usr/local/lib/node_modules/sequelize-cli/lib/gulpfile.js
Finished 'db:migrate' after 161 ms这意味着它没有找到任何迁移文件。数据库中未出现表,也未创建sequelizeMeta表。
怎么了?
发布于 2015-10-15 23:45:01
您可以尝试在根目录中创建一个.sequelizerc文件,将其指向正确的迁移文件夹:
var path = require('path');
module.exports = {
'config': path.resolve('path/to/folder', 'config/config.json'),
'migrations-path': path.resolve('path/to/folder', 'migrations'),
'models-path': path.resolve('path/to/folder, 'models')
}创建文件后运行sequelize init
https://stackoverflow.com/questions/32072674
复制相似问题