我创建了此迁移文件:
'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('note_tags', {
id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
note_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'notes',
key: 'id',
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
},
tag_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'tags',
key: 'id',
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
},
});
await queryInterface.addIndex('note_tags', ['note_id']);
return queryInterface.addIndex('note_tags', ['tag_id']);
},
down(queryInterface) {
return queryInterface.dropTable('note_tags');
},
};
现在,当我运行应用程序时,出现此错误:
UnhandledPromiseRejectionWarning: SequelizeDatabaseError: relation "note_tags_note_id" already exists
该索引确实存在于我的本地数据库中。我不确定该怎么做,因为我对supplier_users
有类似的东西,但是索引为supplier_users_supplier_id
,但是从来没有遇到这个问题。
我该如何解决?
答案 0 :(得分:0)
我刚刚从数据库中删除了索引,然后重新启动了应用程序。