Duplicate Entry For Key Primary Error
Contents |
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 counterpoint duplicate primary key value Us Learn more about Stack Overflow the company Business Learn more about hiring
Duplicate Entry For Key Primary Auto Increment
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the duplicate entry for key primary in mysql Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up MySQL duplicate entry error even though
Mysql Duplicate Entry For Key Primary Auto_increment
there is no duplicate entry up vote 5 down vote favorite 1 I am using MySQL 5.1.56, MyISAM. My table looks like this: CREATE TABLE IF NOT EXISTS `my_table` ( `number` int(11) NOT NULL, `name` varchar(50) NOT NULL, `money` int(11) NOT NULL, PRIMARY KEY (`number`,`name`) ) ENGINE=MyISAM; It contains these two rows: INSERT INTO `my_table` (`number`, `name`, `money`) VALUES (1, 'S. Name', 150), (2, 'Another Name', 284); duplicate entry 1 for key primary Now I am trying to insert another row: INSERT INTO `my_table` (`number`, `name`, `money`) VALUES (2, 'S. Name', 240); And MySQL just won't insert it while telling me this: #1062 - Duplicate entry '2-S. Name' for key 'PRIMARY' I really don't understand it. The primary key is on the first two columns (both of them), so the row I am trying to insert HAS a unique primary key, doesn't it? I tried to repair the table, I tried to optimize the table, all to no avail. Also please note that I cannot change from MyISAM to InnoDB. Am I missing something or is this a bug of MySQL or MyISAM? Thanks. To summarize and point out where I think is the problem (even though there shouldn't be): Table has primary key on two columns. I am trying to insert a row with a new combination of values in these two columns, but value in column one is already in some row and value in column two is already in another row. But they are not anywhere combined, so I believe this is supposed to work and I am very confused to see that it doesn't. mysql primar
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
Mysql Error 1062 Duplicate Entry For Key Primary
Stack Overflow the company Business Learn more about hiring developers or posting ads with
#1062 - Duplicate Entry '' For Key
us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is duplicate entry '1' for key 'primary' mysql a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up #1062 - Duplicate entry for key 'PRIMARY' up vote 4 down vote favorite 3 http://stackoverflow.com/questions/13132535/mysql-duplicate-entry-error-even-though-there-is-no-duplicate-entry 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 values into the table, in which the name and http://stackoverflow.com/questions/11638505/1062-duplicate-entry-for-key-primary 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:10 well in my phpmyadmin I cannot click on the primary key for both name
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the http://stackoverflow.com/questions/12075445/duplicate-entry-for-key-primary-in-mysql 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 4.7 million programmers, just like you, helping each other. Join duplicate entry them; it only takes a minute: Sign up Duplicate entry for key 'PRIMARY' in mysql up vote 6 down vote favorite 2 I have a table called tbl_jobs that stores the meta data of some background jobs running in the application. The schema is like : CREATE TABLE `tbl_jobs` ( `type` varchar(30) NOT NULL DEFAULT '', `last_run_on` datetime NOT for key primary NULL, `records_updated` text, PRIMARY KEY (`type`,`last_run_on`), UNIQUE KEY `index2` (`type`,`last_run_on`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1$$ Whenever a job runs it makes an entry in the table with the type which is a unique identifier for different jobs, run time and the records updated in that run. There are two different jobs that run at same time with types : MAILER_UNLOCKED_REWARDS and MAILER_ALMOST_UNLOCKED. When these jobs try to insert their entries with the same timestamp only one of them gets inserted and the other throws a Duplicate Entry for key error. For instance the two jobs ran the following : INSERT INTO tbl_jobs (type, last_run_on, records_updated) VALUES ('MAILER_ALMOST_UNLOCKED', '2012-08-22 19:10:00', 'f8a35230fb214989ac75bf11c085aa28:b591426df4f340ecbce5a63c2a5a0174') that ran successfully but when the second job ran the insert command INSERT INTO tbl_jobs (type, last_run_on, records_updated) VALUES ('MAILER_UNLOCKED_REWARDS', '2012-08-22 19:10:00', '8a003e8934c07f040134c30959c40009:59bcc21b33a0466e8e5dc50443beb945') It threw the error Duplicate entry 'M-2012-08-22 19:10:00' for key 'PRIMARY' The primary key is combination of type and last_run_on columns. If I delete the entry for the first job the insertion succeeds, i.e it is asking for timestamp alone to be unique. Ho