Warning
Error Code: 1264

MySQL Error 1264: Out of Range Value

📦 MySQL
📋

Description

This error occurs when you attempt to insert or update a value into a column that exceeds its defined data type's range or capacity. MySQL issues this warning (which can become an error in strict SQL mode) when a numeric value is too large or too small, a string is too long, or a date/time value is invalid for its target column.
💬

Error Message

Out of range value for column '%s' at row %ld
🔍

Known Causes

4 known causes
⚠️
Numeric Overflow/Underflow
Attempting to store a number (integer, decimal, float) that is larger or smaller than the limits defined by the column's data type (e.g., TINYINT, INT, DECIMAL).
⚠️
String Length Exceeded
Trying to insert a string value into a VARCHAR or CHAR column that is longer than the column's maximum allowed length.
⚠️
Negative Value in Unsigned Column
Inserting a negative number into a column that has been defined with the UNSIGNED attribute, which only permits zero or positive values.
⚠️
Invalid Date/Time Value
Providing a date, time, or datetime value that is malformed or falls outside the valid range supported by the respective column type.
🛠️

Solutions

5 solutions available

1. Use Appropriate Data Type medium

Change column to type that fits your data

1
Check current column type and limits
-- Integer type ranges:
-- TINYINT: -128 to 127 (UNSIGNED: 0 to 255)
-- SMALLINT: -32768 to 32767
-- MEDIUMINT: -8388608 to 8388607
-- INT: -2147483648 to 2147483647
-- BIGINT: -9223372036854775808 to 9223372036854775807
2
Change to larger type
-- If INT is too small, use BIGINT:
ALTER TABLE your_table MODIFY COLUMN amount BIGINT;
3
For decimal values
-- DECIMAL with precision:
ALTER TABLE your_table MODIFY COLUMN price DECIMAL(15, 2);

2. Fix the Data Value easy

Adjust value to fit within column range

1
Check valid range for your column
DESCRIBE your_table;
2
Use value within range
-- Wrong: TINYINT column, value 300
-- INSERT INTO items (quantity) VALUES (300);

-- Right: value within TINYINT range (max 127 signed)
INSERT INTO items (quantity) VALUES (127);

-- Or use TINYINT UNSIGNED (max 255)
ALTER TABLE items MODIFY quantity TINYINT UNSIGNED;

3. Handle Overflow in Application easy

Validate data before inserting

1
Add validation in application code
// JavaScript example
function validateQuantity(value) {
  const MAX_INT = 2147483647;
  const MIN_INT = -2147483648;
  
  if (value > MAX_INT || value < MIN_INT) {
    throw new Error('Value out of range');
  }
  return value;
}

4. Use UNSIGNED for Positive Numbers easy

Double positive range by removing negatives

1
Change to UNSIGNED if values are always positive
-- INT: -2147483648 to 2147483647
-- INT UNSIGNED: 0 to 4294967295

ALTER TABLE users MODIFY COLUMN points INT UNSIGNED;

5. Disable Strict Mode (Not Recommended) advanced

Allow silent truncation

1
Check current SQL mode
SELECT @@sql_mode;
2
Remove strict mode
SET SESSION sql_mode = '';
-- or remove STRICT_TRANS_TABLES from the mode list
🔗

Related Errors

5 related errors