I am getting a very weird duplicate entry error when no values are even identical...
INSERT INTO offer_status (id,user_id,sql_id,disabled)
VALUES ('8854011812','8854','11812','0')
Returns:
#1062
- Duplicate entry '2147483647' for key 'PRIMARY'
This does not make sense to me at all!
Note: This code is not normally executed, I am just trying to debug. Normally in my PHP I have:
$offer=$campid;
$id=$user_id.'0'.$offer;
$sql="INSERT INTO offer_status (id,user_id,sql_id,disabled) VALUES (?,?,?,?)
ON DUPLICATE KEY UPDATE disabled=VALUES(disabled)";
$db->prepare($sql)->execute(array($id, $user_id, $offer, 0));
id
is the primary key. What is going on here?
Added: Result of DESC offer_status
:
Field Type Null Key Default Extra
id int(12) NO PRI NULL
user_id int(12) NO NULL
sql_id int(12) NO MUL NULL
favor tinyint(4) NO 0
disabled tinyint(4) NO 0
pref int(2) NO 0
8854011812
is out of int
range. It will be replaced by the max int
number which is 2147483647
.
The second time you insert a value greather than the int
max, you will get a duplicate key error.
If you need such high numbers you can change your data type to bigint
.
Oh i see. Since you have mentioned that ID
is the primary, I guess the data type of which is int
and which the maximum value for SIGNED INT
is 2147483647
. You should have change the data type to decimal(15,0)
or VARCHAR(15)
so the value will be cattered.
The value you are inserting 8854011812
is kinda out of range to which an int
can hold.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With