Welcome Guest, Not a member yet? Register   Sign In
Frequent duplicate entry error on ci_sessions table
#1

From time to time, while developing and testing, I get the following error:

A Database Error Occurred

Error Number: 1062

Duplicate entry '[a long key]' for key 'PRIMARY'

INSERT INTO `ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('[same long key]', 'fe80::1', 1435884132, '__ci_last_regenerate|i:1435884132;')

Filename: libraries/Session/drivers/Session_database_driver.php

Line Number: 220

Here is the spec for my sessions table

CREATE TABLE `ci_sessions` (
`id` varchar(40) NOT NULL DEFAULT '0',
`ip_address` varchar(45) NOT NULL DEFAULT '0',
`timestamp` int(10) unsigned NOT NULL DEFAULT '0',
`data` blob NOT NULL,
PRIMARY KEY (`id`),
KEY `ci_sessions_timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

And here is my configuration for sessions:

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;


Are there approaches to avoiding this kind of error? Do I have my sessions misconfigured?

Thanks for your help in this.
Reply
#2

(07-02-2015, 05:54 PM)Shawn Wrote: From time to time, while developing and testing, I get the following error:

A Database Error Occurred

Error Number: 1062

Duplicate entry '[a long key]' for key 'PRIMARY'

INSERT INTO `ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('[same long key]', 'fe80::1', 1435884132, '__ci_last_regenerate|i:1435884132;')

Filename: libraries/Session/drivers/Session_database_driver.php

Line Number: 220

Here is the spec for my sessions table

CREATE TABLE `ci_sessions` (
 `id` varchar(40) NOT NULL DEFAULT '0',
 `ip_address` varchar(45) NOT NULL DEFAULT '0',
 `timestamp` int(10) unsigned NOT NULL DEFAULT '0',
 `data` blob NOT NULL,
 PRIMARY KEY (`id`),
 KEY `ci_sessions_timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

And here is my configuration for sessions:

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;


Are there approaches to avoiding this kind of error?  Do I have my sessions misconfigured?

Thanks for your help in this.

You didn't change the "primary key(id)" part of the creation query to "primary key(id, ip_address)" like the documentation suggests.

Regards,
Igor Kroeber
Reply




Theme © iAndrew 2016 - Forum software by © MyBB