dublicate key mysql_Duplicate key error in MySQL (Duplicate key name '')

The below query is resulting in an error. I created this query in MySQL Workbench

Error

SQL query:

-- -----------------------------------------------------

-- Table `smsdb`.`IntSupervisor`

-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `smsdb`.`IntSupervisor` (

`int_supr_id` VARCHAR( 32 ) NOT NULL ,

`cent_id` INT NOT NULL ,

INDEX `fk_IntSupervisor_Person1_idx` ( `int_supr_id` ASC ) ,

INDEX `fk_IntSupervisor_Center1_idx` ( `cent_id` ASC ) ,

PRIMARY KEY ( `int_supr_id` ) ,

CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` )

REFERENCES `smsdb`.`Staff` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT ,

CONSTRAINT `fk_center_id` FOREIGN KEY ( `cent_id` )

REFERENCES `smsdb`.`Center` (`cent_id`

) ON DELETE CASCADE ON UPDATE RESTRICT

) ENGINE = InnoDB;

I got an error message on execution:

MySQL said: Documentation

#1022 - Can‘t write; duplicate key in table ‘intsupervisor‘

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.

PRIMARY KEY ( `int_supr_id` ) ,

CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` )

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 ...

PRIMARY KEY ( `int_supr_id` ) ,

CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` )

With the following:

CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` )

(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 导致报错。后来改为一样    导入数据通过

原文:http://blog.csdn.net/baicp3/article/details/21749503

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值