본문 바로가기
MySql

MySQL MySql can't make column auto_increment

by 베이스 공부 2020. 10. 14.
반응형

"Id"(PK), "KlantId", "Datum", "BestellingsTypeId"라는 4 개의 열이있는 "Bestelling"테이블이 있습니다. 이제 열 Id를 auto_increment로 만들고 싶습니다. 그러나 그렇게하려고 할 때 이 오류가 발생합니다.

ERROR 1062: ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '1' for key 'PRIMARY'

SQL Statement:

ALTER TABLE `aafest`.`aafest_bestelling` CHANGE COLUMN `Id` `Id` INT(11) NOT NULL AUTO_INCREMENT



ERROR: Error when running failback script. Details follow.



ERROR 1046: No database selected

SQL Statement:

CREATE TABLE `aafest_bestelling` (

  `Id` int(11) NOT NULL,

  `KlantId` int(11) DEFAULT NULL,

  `Datum` date DEFAULT NULL,

  `BestellingstypeId` int(11) DEFAULT NULL,

  PRIMARY KEY (`Id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1

누구나 아이디어가 있습니까?

 

해결 방법

 

이는 테이블에 ID가 0 (또는 음수) 인 기존 레코드가 포함 된 경우 발생합니다. 양수 값을 사용하도록 모든 기존 레코드를 업데이트하면 해당 열에 auto_increment를 설정할 수 있습니다.


 

참조 페이지 https://stackoverflow.com/questions/5402949

 

 

반응형

댓글