Error Code: 1062. Duplicate entry '1' for key 'PRIMARY'

后端 未结 8 2040
既然无缘
既然无缘 2020-12-01 03:55

I have a problem on this error message, when i try this:

INSERT INTO `PROGETTO`.`UFFICIO-INFORMAZIONI` (`ID`, `viale`, `num_civico`,  
`data_apertura`, `data         


        
相关标签:
8条回答
  • 2020-12-01 04:29

    The main reason why the error has been generated is because there is already an existing value of 1 for the column ID in which you define it as PRIMARY KEY (values are unique) in the table you are inserting.

    Why not set the column ID as AUTO_INCREMENT?

    CREATE  TABLE IF NOT EXISTS `PROGETTO`.`UFFICIO-INFORMAZIONI` (
      `ID` INT(11) NOT NULL AUTO_INCREMENT,
      `viale` VARCHAR(45) NULL ,
       .....
    

    and when you are inserting record, you can now skip the column ID

    INSERT INTO `PROGETTO`.`UFFICIO-INFORMAZIONI` (`viale`, `num_civico`, ...) 
    VALUES ('Viale Cogel ', '120', ...)
    
    0 讨论(0)
  • 2020-12-01 04:32

    If you are trying to populate a table from a SQL dump, make sure that the table listed in the "INSERT INTO" statements of the dump is the same one you are trying to populate. Opening "MyTable" and importing with a SQL dump will throw exactly that kind of error if the dump is trying to put entries into "MyOtherTable", which may already have entries.

    0 讨论(0)
提交回复
热议问题