【问题标题】:Sequelize index already exist error appearing when I run application运行应用程序时出现 Sequelize index already exists 错误
【发布时间】: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


    【解决方案1】:

    我刚刚从数据库中删除了索引并重新启动了应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-14
      • 2018-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多