Primary Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the
Mysql Error 1062 Duplicate Entry For Key Primary
workings and policies of this site About Us Learn more about error code 1062 duplicate entry for key primary Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions duplicate entry for key 'primary' mysql Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other.
Duplicate Entry For Key Primary Error
Join them; it only takes a minute: Sign up Error Code: 1062. Duplicate entry '1' for key 'PRIMARY' up vote 9 down vote favorite 5 I have a problem on this error message, when i try this: INSERT INTO `PROGETTO`.`UFFICIO-INFORMAZIONI` (`ID`, `viale`, `num_civico`, `data_apertura`, `data_chiusura`, `orario_apertura`, `orario_chiusura`, `telefono`, `mail`, `web`, `Nome-paese`, `Comune`) VALUES (1, 'Viale Cogel ', '120', '2012-05-21',
Duplicate Entry '1' For Key 'primary' Mysql
'2012-09-30', '08:00', '23:30', '461801243', 'informazioni@bolzano.it', 'Bolzanoturismo.it', 'Bolzano', 'BZ') Error Code: 1062. Duplicate entry '1' for key 'PRIMARY' I haven't auto_increment data, PLEASE HELP me! This is the table related, UFFICIO-INFORMAZIONI CREATE TABLE IF NOT EXISTS `PROGETTO`.`UFFICIO-INFORMAZIONI` ( `ID` INT(11) NOT NULL , `viale` VARCHAR(45) NULL , `num_civico` VARCHAR(5) NULL , `data_apertura` DATE NULL , `data_chiusura` DATE NULL , `orario_apertura` TIME NULL , `orario_chiusura` TIME NULL , `telefono` VARCHAR(15) NULL , `mail` VARCHAR(100) NULL , `web` VARCHAR(100) NULL , `Nome-paese` VARCHAR(45) NOT NULL , `Comune` CHAR(2) NOT NULL , PRIMARY KEY (`ID`) , INDEX `Nome_paese` (`Nome-paese` ASC) , INDEX `Comune` (`Comune` ASC) , CONSTRAINT `Nome_paese` FOREIGN KEY (`Nome-paese` ) REFERENCES `PROGETTO`.`PAESE` (`Nome-paese` ) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `Comune` FOREIGN KEY (`Comune` ) REFERENCES `PROGETTO`.`PAESE` (`Comune` ) ON DELETE NO ACTION ON UPDATE CASCADE) ENGINE = InnoDB INSERT INTO INSERT INTO `PROGETTO`.`UFFICIO-INFORMAZIONI` (`ID`, `viale`, `num_civico`, `data_apertura`, `data_chiusura`, `orario_apertura`, `orario_chiusura`, `telefono`, `mail`, `web`, `Nome-paese`, `Comune`) VALUES (1, 'Viale Cogel ', '120', '2012-05-21', '2012-09-30', '08:00', '23:30', '461801243', 'informazioni@bolzano.it', 'Bolzanoturismo.it', 'Bolzano', 'BZ'); INSERT INTO `PROGETTO`.`UFFIC
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us #1062 - duplicate entry '1' for key 'primary' phpmyadmin import Learn more about Stack Overflow the company Business Learn more about hiring developers
Duplicate Entry '0' For Key 'primary' Mysql
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow #1062 - duplicate entry '1' for key 'primary' wordpress Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up #1062 - Duplicate entry for key 'PRIMARY' up http://stackoverflow.com/questions/14628269/error-code-1062-duplicate-entry-1-for-key-primary vote 4 down vote favorite 3 So my MySQL database is behaving a little bit wierd. This is my table: Name shares id price indvprc cat 2 4 81 0 goog 4 4 20 20 fb 4 9 20 20 I'm getting this #1062 error when I try to insert into the table. So I looked into it further and realized that when I try to insert http://stackoverflow.com/questions/11638505/1062-duplicate-entry-for-key-primary values into the table, in which the name and shares values are the same, it will return the #1062 error. For example, If i inserted: fb 4 6 20 20 It would return an error. But if i changed the shares number to 6, it would run fine. Is it because of one of my columns that could be unique, or is it just something with mysql? mysql sql mysql-error-1062 share|improve this question asked Jul 24 '12 at 20:05 irosenb 1431622 1 what is the primary key on your table? You cannot have duplicate values in a primary key field. A primary key can also consist of multiple fields so what fields are in your key? –bluefeet♦ Jul 24 '12 at 20:06 Don't know for sure, but could your database have formed a relationship between shares and id ? take a look in phpMyAdmin and see what you can find.... –dykeag Jul 24 '12 at 20:08 1 Most likely you primary key is composed by the columns Name and shares. That means that the combination of both columns must be unique (in your example, the combination fb, 4 already exists) –Lamak Jul 24 '12 at 20:1
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business http://stackoverflow.com/questions/12179770/mysql-1062-duplicate-entry-0-for-key-primary Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation http://stackoverflow.com/questions/5860074/phpmyadmin-export-import-results-in-duplicate-primary-key-error Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up MySQL 1062 - Duplicate entry '0' for key 'PRIMARY' up vote 18 down vote favorite 3 I have following table in MySQL version 5.5.24 DROP duplicate entry TABLE IF EXISTS `momento_distribution`; CREATE TABLE IF NOT EXISTS `momento_distribution` ( `momento_id` INT(11) NOT NULL, `momento_idmember` INT(11) NOT NULL, `created_at` DATETIME DEFAULT NULL, `updated_at` DATETIME DEFAULT NULL, `unread` TINYINT(1) DEFAULT '1', `accepted` VARCHAR(10) NOT NULL DEFAULT 'pending', `ext_member` VARCHAR(255) DEFAULT NULL, PRIMARY KEY (`momento_id`, `momento_idmember`), KEY `momento_distribution_FI_2` (`momento_idmember`), KEY `accepted` (`accepted`, `ext_member`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; It have lot of data with many-to-one relation with two other table with ondelete=restrict and onupdate=restrict. Now I need for key 'primary' to change the structure and introduce separate primary key in the table, while keeping existing relation and data. For that, I executed following query ALTER TABLE `momento_distribution` ADD `id` INT( 11 ) NOT NULL FIRST; ALTER TABLE `momento_distribution` DROP PRIMARY KEY , ADD PRIMARY KEY ( `id` ); Unfortunately, Second query failed with following error 1062 - Duplicate entry '0' for key 'PRIMARY' Can someone please point out the issue? I guess issue is the existing relation but I don't want to loose existing relation or data, which have several thousand rows. Is there any way to do this without loosing data? Edit By Kapil: By viewing data, I got that newly created column have value '0' in it. Probably this is not allowing to change the PK due to duplicate records (in new PK) I've more that 8000 rows so cant change it manually. IS there any way to assign rowid to new PK? mysql sql share|improve this question edited Mar 5 '15 at 8:48 Gautam Somani 1641111 asked Aug 29 '12 at 14:03 Kapil Sharma 2,69941951 add a comment| 3 Answers 3 active oldest votes up vote 7 down vote accepted On the mysql console; run the following queries. 1. SHOW CREATE TABLE momento_distribution Check for the line that looks something like CONSTRAINT `momento_distribution_FK_1` FOREIGN KEY (`momento_id`) REFERENCES `momento` (`id`) It may be
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up phpMyAdmin export/import results in duplicate primary key error up vote 2 down vote favorite 1 I want to globally replace all instances of my site url in the Wordpress MySQL database with a new site url. To do that, I'm using phpMyAdmin to export the database to a .sql file, then doing a global replace in a text editor, then using phpMyAdmin to import the .sql file. During the import, I'm encountering a duplicate entry for primary key error. Trying to debug this, I exported the file, then imported the identical file, making no changes and I still get the same error. I appreciate any help solving this. -- -- Dumping data for table `wp_comments` -- INSERT INTO `wp_comments` (`comment_ID`, `comment_post_ID`, `comment_author`, `comment_author_email` ,`comment_author_url`, `comment_author_IP`, `comment_date`, `comment_date_gmt` ,`comment_content`, `comment_karma`, `comment_approved`, `comment_agent` ,`comment_type`, `comment_parent`, `user_id`) VALUES (1, 1, 'Mr WordPress', '' ,'http://wordpress.org/', '', '2011-04-28 00:49:55', '2011-04-28 00:49:55' ,'Hi, this is a comment.
To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.' , 0, 'post-trashed', '', '', 0, 0 ) ; MySQL said: #1062 - Duplicate entry '1' for key 'PRIMARY' mysql wordpress insert phpmyadmin share|improve this question edited May 2 '11 at 17:20 Johan 49k16106202 asked May 2 '11 at 17:06 LandedGently 4531616 @Johan - thanks for the edit to make the code in my question more legible. –LandedGent