DuplicatekeyerrorinMySQL(Duplicatekeyname'&a

WBOY
풀어 주다: 2016-06-07 15:54:05
원래의
1169명이 탐색했습니다.

The 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

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

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!