我已经编写了续集器迁移javascript来对表中的现有列进行更改,但是当我运行命令sequelizer db:migrate
时
,它给出了错误
== 20170212050240-alter_col_tag_subject: migrating =======
Unhandled rejection SequelizeBaseError: SQLITE_ERROR: no such table: subject_tags
== 20170212050240-alter_col_tag_subject: migrated (0.241s)
这是迁移文件的代码
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return [
queryInterface.changeColumn(
'subject_tags',
'tag',
{
type: Sequelize.STRING,
unique: true,
validate: {
len: [1, 250]
}
}
),
queryInterface.changeColumn(
'subject_tags',
'tag_description',
{
type: Sequelize.STRING,
allowNull: false,
validate: {
len: [1, 250]
}
}
),
queryInterface.changeColumn(
'subject_tags',
'associated_subject',
{
type: Sequelize.STRING,
allowNull: false,
validate: {
len: [1, 250]
}
}
)
];
},
down: function (queryInterface, Sequelize) {
}
};
有人知道我遇到这个问题的原因吗?
答案 0 :(得分:1)
引用sdepold
嘿伙计们。迁移函数应该返回promises。所以 如果你想在迁移中做多件事,只需返回一个 链子承诺这样:
return queryInterface.removeColumn('users', 'email').then(function () {
return queryInterface.removeColumn('users', 'encryptedPassword');
});
因此正确的代码
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.changeColumn(
'subject_tags',
'tag',
{
type: Sequelize.STRING,
unique: true,
validate: {
len: [1, 250]
}
}
). then( function () {
return queryInterface.changeColumn(
#.......
);
}).then( function () {
return queryInterface.changeColumn(
#.......
);
}) ;
希望这回答这个问题。