Hi, Can someone please tell me how to fix this error below: This comes up when inserting a record. Duplicate entry '0-1' for key 2 query is this: INSERT INTO topics ( ID_TOPIC , isSticky , ID_BOARD, ID_FIRST_MSG , ID_LAST_MSG, ID_MEMBER_STARTED , ID_MEMBER_UPDATED , ID_POLL , numReplies , numViews , locked ) VALUES ('', 0, '1', '7',0, '15', 0, 0, 0, '551', 0) Table structure is this: ID_TOPIC mediumint(8) unsigned NOT NULL auto_increment, isSticky tinyint(4) NOT NULL default '0', ID_BOARD smallint(5) unsigned NOT NULL default '0', ID_FIRST_MSG int(10) unsigned NOT NULL default '0', ID_LAST_MSG int(10) unsigned NOT NULL default '0', ID_MEMBER_STARTED mediumint(8) unsigned NOT NULL default '0', ID_MEMBER_UPDATED mediumint(8) unsigned NOT NULL default '0', ID_POLL mediumint(8) unsigned NOT NULL default '0', numReplies int(10) unsigned NOT NULL default '0', numViews int(10) unsigned NOT NULL default '0', locked tinyint(4) NOT NULL default '0', PRIMARY KEY ( ID_TOPIC ), UNIQUE KEY lastMessage ( ID_LAST_MSG , ID_BOARD ), UNIQUE KEY firstMessage ( ID_FIRST_MSG , ID_BOARD ), UNIQUE KEY poll ( ID_POLL , ID_TOPIC ), KEY isSticky ( isSticky ), KEY ID_BOARD ( ID_BOARD ) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; Which values I need to change in above query so it works? Thanks
Below is the backup of this table. Both records have "0" for sticky, and "1" for ID_BOARD. If the error is with these 2 fields, then why is the second record inserted properly? INSERT INTO topics ( ID_TOPIC , isSticky , ID_BOARD , ID_FIRST_MSG , ID_LAST_MSG , ID_MEMBER_STARTED , ID_MEMBER_UPDATED , ID_POLL , numReplies , numViews , locked ) VALUES (1, 0, 1, 1, 2, 0, 1, 0, 1, 1, 0), (2, 0, 1, 3, 3, 1, 1, 0, 0, 0, 0); I think it's some other field, but not sure which one... regards
Ok, This is solved. The problem was in ID_FIRST_MSG , ID_LAST_MSG fields. Value for those records are 0,0 and new records I was adding were also 0,0 . Changed it to -1,-1 and updated later. Thanks