本文介绍了MySQL“索引名称不正确..."错误(唯一外键)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MySQL不断收到错误消息错误的索引名称'f7'",并将其缩小到以下范围:

I keep getting an error "Incorrect index name 'f7'" using MySQL and I've narrowed it down to the following:

首先,我创建表

CREATE TABLE testTable (
    id INTEGER PRIMARY KEY AUTO_INCREMENT,
    f7 INTEGER NOT NULL,
    FOREIGN KEY (f7) REFERENCES testTable2 (id) ON DELETE CASCADE ON UPDATE CASCADE,
) ENGINE=InnoDB;

然后在其他地方

ALTER TABLE testTable ADD UNIQUE f7;

使我相信,这与重复索引有关? )我只是不知道如何解决它.非常感谢.

This has led me to believe that this has to do with a duplicate index (?) I just can't figure out how to fix it. Many thanks.

推荐答案

为其命名,以免与外键索引冲突

Give it a name, so it doesn't conflict with the foreign Key index

ALTER TABLE `testtable`  ADD UNIQUE INDEX `foo` (`f7`);

这篇关于MySQL“索引名称不正确..."错误(唯一外键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 13:13