SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 24/09/2015, 04:43 PM   #1
norton2
Huge Clucker
 
Join Date: Jul 2013
Posts: 431
Reputation: 9
Default Duplicate Key!

ERROR MYSQL:
HTML Code:
EndCB();Log("11:41:48","CMySQLQuery::Execute[OnVehInsert]",1,"(error #1062) Duplicate entry '1' for key 'PRIMARY'",1);
HTML Code:
CREATE TABLE IF NOT EXISTS `vehicles` (
  `ID` int(11) NOT NULL,
  `Owner` int(11) NOT NULL,
  `Model` int(6) NOT NULL,
  `PosX` float NOT NULL,
  `PosY` float NOT NULL,
  `PosZ` float NOT NULL,
  `VAngle` float NOT NULL,
  `ServerID` int(6) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
HTML Code:
ALTER TABLE `vehicles`
  MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;
norton2 is offline   Reply With Quote
Old 24/09/2015, 04:58 PM   #2
Aly
Huge Clucker
 
Join Date: Oct 2012
Posts: 219
Reputation: 11
Default Re: Duplicate Key!

Try this:

Code:
CREATE TABLE IF NOT EXISTS `vehicles` (
  `ID` int(11) AUTO_INCREMENT,
  `Owner` int(11) NOT NULL,
  `Model` int(6) NOT NULL,
  `PosX` float NOT NULL,
  `PosY` float NOT NULL,
  `PosZ` float NOT NULL,
  `VAngle` float NOT NULL,
  `ServerID` int(6) NOT NULL,
   PRIMARY KEY(`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The other part should not be needed.
Aly is offline   Reply With Quote
Old 24/09/2015, 05:05 PM   #3
norton2
Huge Clucker
 
Join Date: Jul 2013
Posts: 431
Reputation: 9
Default Re: Duplicate Key!

MYSQL ERROR:
HTML Code:
--
-- Indexes for table `vehicles`
--
ALTER TABLE `vehicles`
  ADD PRIMARY KEY (`ID`);
#1068 - Multiple primary key defined
norton2 is offline   Reply With Quote
Old 24/09/2015, 05:11 PM   #4
Aly
Huge Clucker
 
Join Date: Oct 2012
Posts: 219
Reputation: 11
Default Re: Duplicate Key!

Code:
CREATE TABLE IF NOT EXISTS `vehicles` (
  `ID` int(11) AUTO_INCREMENT,
  `Owner` int(11) NOT NULL,
  `Model` int(6) NOT NULL,
  `PosX` float NOT NULL,
  `PosY` float NOT NULL,
  `PosZ` float NOT NULL,
  `VAngle` float NOT NULL,
  `ServerID` int(6) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Go for this one then and let me know what is your current PRIMARY KEY.
Aly is offline   Reply With Quote
Old 24/09/2015, 05:15 PM   #5
norton2
Huge Clucker
 
Join Date: Jul 2013
Posts: 431
Reputation: 9
Default Re: Duplicate Key!

DataBase SQL:
HTML Code:
--
-- Indexes for table `vehicles`
--
ALTER TABLE `vehicles`
  ADD PRIMARY KEY (`ID`);
HTML Code:
--
-- AUTO_INCREMENT for table `vehicles`
--
ALTER TABLE `vehicles`
  MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;
norton2 is offline   Reply With Quote
Old 24/09/2015, 05:19 PM   #6
Aly
Huge Clucker
 
Join Date: Oct 2012
Posts: 219
Reputation: 11
Default Re: Duplicate Key!

Just delete the current database and use this and don't alter the table anymore is not needed.

Code:
CREATE TABLE IF NOT EXISTS `vehicles` (
  `ID` int(11) AUTO_INCREMENT,
  `Owner` int(11) NOT NULL,
  `Model` int(6) NOT NULL,
  `PosX` float NOT NULL,
  `PosY` float NOT NULL,
  `PosZ` float NOT NULL,
  `VAngle` float NOT NULL,
  `ServerID` int(6) NOT NULL,
   PRIMARY KEY(`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Or you can put this lines on your gm.
Aly is offline   Reply With Quote
Old 24/09/2015, 05:24 PM   #7
norton2
Huge Clucker
 
Join Date: Jul 2013
Posts: 431
Reputation: 9
Default Re: Duplicate Key!

Don't work!
HTML Code:
EndCB();Log("12:24:27","CMySQLQuery::Execute[OnVehInsert]",1,"(error #1062) Duplicate entry '1' for key 'PRIMARY'",1);
norton2 is offline   Reply With Quote
Old 24/09/2015, 05:36 PM   #8
Aly
Huge Clucker
 
Join Date: Oct 2012
Posts: 219
Reputation: 11
Default Re: Duplicate Key!

Show me the code(the insert query that is generating this error).I guess is "OnVehInsert".
Aly is offline   Reply With Quote
Old 24/09/2015, 05:37 PM   #9
rappy93
Huge Clucker
 
rappy93's Avatar
 
Join Date: Mar 2012
Location: Romania
Posts: 449
Reputation: 18
Default Re: Duplicate Key!

Is your ID column set to auto_increment?
__________________
Nothing.
rappy93 is offline   Reply With Quote
Old 24/09/2015, 05:42 PM   #10
norton2
Huge Clucker
 
Join Date: Jul 2013
Posts: 431
Reputation: 9
Default Re: Duplicate Key!

Rappy@: Yes

Aly:
HTML Code:
stock OnVehInsert(r, playerid)
{
    new ORM:ormid = Veh[r][ORM_ID] = orm_create("vehicles",MySQLCon);
    orm_addvar_int(ormid, Veh[r][ID], "ID"); //this is the key
    orm_addvar_int(ormid, Veh[r][Owner], "Owner");
    orm_addvar_int(ormid, Veh[r][Model], "Model");
    orm_addvar_float(ormid, Veh[r][PosX], "PosX");
    orm_addvar_float(ormid, Veh[r][PosY], "PosY");
    orm_addvar_float(ormid, Veh[r][PosZ], "PosZ");
    orm_addvar_float(ormid, Veh[r][VAngle], "VAngle");
    orm_addvar_int(ormid, Veh[r][ServerID], "ServerID");
    orm_setkey(ormid,"ID");
}
norton2 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate Actors bug Admigo Bug Reports 2 06/05/2015 12:24 AM
Duplicate stats. Nezinuu Scripting Help 3 07/02/2015 04:15 PM
[Help] Duplicate Functions iryston Scripting Help 10 05/11/2013 03:15 PM
duplicate car leetboi Scripting Help 2 26/11/2012 07:04 PM
GM duplicate objects cruising Scripting Help 7 12/10/2011 07:49 PM


All times are GMT. The time now is 01:35 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.