【发布时间】:2019-12-09 01:23:07
【问题描述】:
我创建了这个迁移文件:
'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 索引,但从来没有遇到过这个问题。
我该如何解决这个问题?
【问题讨论】:
标签: javascript node.js indexing sequelize.js