CodeIgniter Forums
sometimes get error Duplicate entry for key 'PRIMARY' - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: sometimes get error Duplicate entry for key 'PRIMARY' (/showthread.php?tid=1274)



sometimes get error Duplicate entry for key 'PRIMARY' - karnadi - 02-24-2015

A Database Error Occurred
Error Number: 1062
Duplicate entry '8873c26193f493433c2107eabf5b0629730d1428' for key 'PRIMARY'
INSERT INTO `asni_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('8873c26193f493433c2107eabf5b0629730d1428', '127.0.0.1', 1424801434, '')
Filename: libraries/Session/drivers/Session_database_driver.php
Line Number: 216

   

should i remove PRIMARY key from field 'id' .... ??


RE: sometimes get error Duplicate entry for key 'PRIMARY' - Narf - 02-24-2015

No, but if you want to use 'sess_match_ip', you must add a unique constraint for id, ip_address ... like explained in the manual: http://www.codeigniter.com/userguide3/libraries/sessions.html#database-driver


RE: sometimes get error Duplicate entry for key 'PRIMARY' - matbeard - 02-26-2015

I'm having the same problem. It seems to be happening on ajax calls, but only over slow connections, perhaps when there is a delay between the initial page content loading and the ajax call being fired.

I'm not using IP address verification, so it's nothing to do with that.

I only noticed the problem when testing a site locally (the basabase is hosted on Amazon RDS though) whilst also uploading a video to YouTube, thus slowing the connection.

The worry is that this issue would affect other users on slow connections.


RE: sometimes get error Duplicate entry for key 'PRIMARY' - karnadi - 02-26-2015

(02-24-2015, 12:25 PM)Narf Wrote: No, but if you want to use 'sess_match_ip', you must add a unique constraint for id, ip_address ... like explained in the manual: http://www.codeigniter.com/userguide3/libraries/sessions.html#database-driver

it works ...
thank you ... 

Code:
PRIMARY KEY (`id`),
UNIQUE INDEX `id_ip_address` (`id`, `ip_address`),
INDEX `timestamp` (`timestamp`)
)