DuplicatekeyerrorinMySQL(Duplicatekeyname'&a
Jun 07, 2016 pm 03:54 PMThe below query is resulting in an error. I created this query in MySQL Workbench ErrorSQL query:-- ------------------------------------------------------- Table `smsdb`.`IntSupervisor`-- ---------------------------------------------------
The below query is resulting in an error. I created this query in MySQL Workbench
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
I got an error message on execution:
1 2 |
|
If anyone has any ideas on how I can resolve this issue, please guide me in the right direction. Thanks!
Welcome to relational databases in MySQL! ;)
You can't have two foreign keys named the same thing across the whole query.
1 |
|
1 |
|
In the above statement, you can't redefine the index type on a single column.
So, how do I fix this annoying error?
Based on the structure of the database, you need to remove one of the two lines above. I'm guessing your linking to another table from the one you are creating, so I recommend replacing ...
1 2 |
|
With the following:
1 |
|
(if the above doesn't work, you likely need to specify a table name for the foreign key)
2.--
-- Table structure for table `payment`
--
DROP TABLE IF EXISTS `payment`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `payment` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`entry_ID` int(11) NOT NULL,
`account_ID` int(11) NOT NULL,
`amount` double NOT NULL,
`pmt_form` varchar(20) NOT NULL,
`reference` varchar(120) DEFAULT NULL,
`COID` int(11) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ID` (`ID`),
KEY `FK_PAYMENT_ACCOUNT` (`account_ID`),
KEY `FK_PAYMENT_ENTRY` (`entry_ID`),
CONSTRAINT `FK_PAYMENT_ACCOUNT` FOREIGN KEY (`account_ID`) REFERENCES `account` (`ID`),
CONSTRAINT `FK_PAYMENT_ENTRY` FOREIGN KEY (`entry_ID`)REFERENCES `register_entry` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
一开始一个是entry_ID 一个是 entry_id 导致报错。后来改为一样 导入数据通过

熱門文章

熱門文章

熱門文章標籤

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

在 Linux 中運行 MySQl(有/沒有帶有 phpmyadmin 的 podman 容器)
