我很抱歉,如果这是一个天真的问题,但我是新的后遗症,我正在尝试与数据库使用QueryInterface。
module.exports = {
up: function (queryInterface, Sequelize) {
queryInterface.addIndex(
'entry',
['create_date', 'username'],
{
indexName: 'create_date_username'
}
);
queryInterface.addIndex(
'entry',
['username'],
{
indexName: 'username'
}
);
queryInterface.addIndex(
'entry',
['source_id', 'source_type'],
{
indexName: 'source_id_source_type'
}
)
.then(() =>
Promise (
????
)
);
},
down: function (queryInterface, Sequelize) {
queryInterface.removeIndex('entry', 'create_date_username');
queryInterface.removeIndex('entry', 'username');
queryInterface.removeIndex('entry', 'source_id_source_type');
}
};但我得到了一个ERROR: Migration 20112-Add-Indices.js (or wrapper) didn't return a promise.,但我是新的,不知道如何确切地回报一个承诺。有人能帮我做一下吗。谢谢。
发布于 2022-07-12 02:22:16
你忘了返回声明了。试着做这样的事情:
up: function (queryInterface, Sequelize) {
return Promise.all([
queryInterface.addIndex(
'entry',
['create_date', 'username'],
{
indexName: 'create_date_username'
}
),
queryInterface.addIndex(
'entry',
['username'],
{
indexName: 'username'
}
),
queryInterface.addIndex(
'entry',
['source_id', 'source_type'],
{
indexName: 'source_id_source_type'
}
)
])
.then(() => ...发布于 2022-07-13 12:14:11
试试看
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addIndex('entry', ['create_date', 'username'], {
indexName: 'create_date_username'
});
await queryInterface.addIndex('entry', ['username'], {
indexName: 'username'
});
await queryInterface.addIndex('entry', ['source_id', 'source_type'], {
indexName: 'source_id_source_type'
});
},
async down(queryInterface, Sequelize) {
await queryInterface.removeIndex('entry', 'create_date_username');
await queryInterface.removeIndex('entry', 'username');
await queryInterface.removeIndex('entry', 'source_id_source_type');
}
};https://stackoverflow.com/questions/72946240
复制相似问题