SA-MP Forums Archive
Duplicate Key! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Duplicate Key! (/showthread.php?tid=589983)



Duplicate Key! - norton2 - 24.09.2015

ERROR MYSQL:
Код HTML:
EndCB();Log("11:41:48","CMySQLQuery::Execute[OnVehInsert]",1,"(error #1062) Duplicate entry '1' for key 'PRIMARY'",1);
Код HTML:
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:
ALTER TABLE `vehicles`
  MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;



Re: Duplicate Key! - Aly - 24.09.2015

Try this:

Код:
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.


Re: Duplicate Key! - norton2 - 24.09.2015

MYSQL ERROR:
Код HTML:
--
-- Indexes for table `vehicles`
--
ALTER TABLE `vehicles`
  ADD PRIMARY KEY (`ID`);
#1068 - Multiple primary key defined



Re: Duplicate Key! - Aly - 24.09.2015

Код:
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.


Re: Duplicate Key! - norton2 - 24.09.2015

DataBase SQL:
Код HTML:
--
-- Indexes for table `vehicles`
--
ALTER TABLE `vehicles`
  ADD PRIMARY KEY (`ID`);
Код HTML:
--
-- AUTO_INCREMENT for table `vehicles`
--
ALTER TABLE `vehicles`
  MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;



Re: Duplicate Key! - Aly - 24.09.2015

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

Код:
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.


Re: Duplicate Key! - norton2 - 24.09.2015

Don't work!
Код HTML:
EndCB();Log("12:24:27","CMySQLQuery::Execute[OnVehInsert]",1,"(error #1062) Duplicate entry '1' for key 'PRIMARY'",1);



Re: Duplicate Key! - Aly - 24.09.2015

Show me the code(the insert query that is generating this error).I guess is "OnVehInsert".


Re: Duplicate Key! - rappy93 - 24.09.2015

Is your ID column set to auto_increment?


Re: Duplicate Key! - norton2 - 24.09.2015

Rappy@: Yes

Aly:
Код HTML:
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");
}