gpt4 book ai didi

node.js - Sequelize 迁移脚本引发错误未处理的拒绝 SequelizeddataBaseError : SQLITE_ERROR: no such table

转载 作者:太空宇宙 更新时间:2023-11-04 00:27:33 24 4
gpt4 key购买 nike

我已经编写了sequelizer迁移javascript来对表中的现有列进行更改,但是当我运行命令sequelizer db:migrate,它给出了错误

== 20170212050240-alter_col_tag_subject:迁移=======未处理的拒绝 SequelizeBaseError:SQLITE_ERROR:没有这样的表:subject_tags== 20170212050240-alter_col_tag_subject:已迁移(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) {

}
};

有人知道我为什么会遇到这个问题吗?

最佳答案

经过大量谷歌搜索后,我在 github 中找到了答案 discussion

引用 sdepold

Hey guys. The migration functions are supposed to return promises. So if you want to do multiple things in a migration, just return a chained promised like this:

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(
#.......
);
}) ;

希望这能回答问题。

关于node.js - Sequelize 迁移脚本引发错误未处理的拒绝 SequelizeddataBaseError : SQLITE_ERROR: no such table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42185152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com