Warning
Error Code: 3859

MySQL Error 3859: Deprecated UNSIGNED Numeric Types

📦 MySQL
📋

Description

This warning indicates that your database schema uses the `UNSIGNED` attribute with `DECIMAL`, `FLOAT`, or `DOUBLE` data types. MySQL has deprecated this usage, and support will be removed in future versions, potentially leading to errors during upgrades or migrations.
💬

Error Message

UNSIGNED for decimal and floating point data types is deprecated and support for it will be removed in a future release.
🔍

Known Causes

3 known causes
⚠️
New Table Creation
A `CREATE TABLE` statement was executed that specifies `UNSIGNED` for `DECIMAL`, `FLOAT`, or `DOUBLE` columns.
⚠️
Altering Existing Columns
An `ALTER TABLE` statement attempted to modify an existing column to include `UNSIGNED` with a decimal or floating-point type.
⚠️
Legacy Schema Scripts
Executing database migration scripts or DDL from older MySQL versions that still contain `UNSIGNED` definitions for these deprecated data type combinations.
🛠️

Solutions

3 solutions available

1. Remove UNSIGNED from DECIMAL and FLOAT/DOUBLE easy

The most direct solution is to remove the UNSIGNED keyword from affected columns.

1
Identify columns using UNSIGNED with DECIMAL, FLOAT, or DOUBLE data types. You can do this by querying the `information_schema`.
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM information_schema.COLUMNS WHERE DATA_TYPE IN ('decimal', 'float', 'double') AND EXTRA LIKE '%unsigned%';
2
For each identified column, alter the table to remove the UNSIGNED attribute. If the column was intended to be strictly positive, you can add a `CHECK` constraint to enforce this, though it's often not strictly necessary if your application logic handles it.
ALTER TABLE your_table_name MODIFY COLUMN your_column_name DECIMAL(10, 2); -- Replace DECIMAL(10, 2) with the original precision and scale
-- OR
ALTER TABLE your_table_name MODIFY COLUMN your_column_name FLOAT; -- Replace FLOAT with the original type (e.g., DOUBLE, REAL)

-- Optional: Add a CHECK constraint for positive values if absolutely required
-- ALTER TABLE your_table_name ADD CONSTRAINT your_column_name_positive CHECK (your_column_name >= 0);
3
Verify the changes by re-querying `information_schema` or by inspecting the table structure.
SHOW CREATE TABLE your_table_name;

2. Update Application Logic to Handle Potential Negative Values medium

Modify application code to ensure it doesn't rely on the implicit unsigned nature of these data types.

1
Review your application's data insertion and retrieval logic. Specifically, look for places where you might be assuming that values stored in `UNSIGNED DECIMAL` or `UNSIGNED FLOAT/DOUBLE` columns will always be non-negative.
2
Implement checks in your application code to handle the possibility of negative values being inserted or retrieved. This might involve adding validation before insertion or checking for negative values after retrieval.
Example in Python (conceptual):
if value < 0:
  raise ValueError("Value cannot be negative.")

# Or after retrieval:
if retrieved_value < 0:
  print("Warning: Negative value encountered where positive was expected.")
3
After ensuring your application logic is robust, proceed with removing the `UNSIGNED` keyword from your MySQL schema as described in Solution 1.

3. Upgrade MySQL to a Version Without This Deprecation Warning advanced

If possible, upgrade to a newer MySQL version where this deprecation is addressed or removed.

1
Check the MySQL release notes for versions that have addressed or removed the deprecation of `UNSIGNED` for `DECIMAL` and floating-point types. Newer versions are generally recommended for bug fixes and new features.
2
Plan and execute a MySQL upgrade. This is a significant operation and requires careful planning, including backups, testing in a staging environment, and a rollback strategy.
Example (conceptual bash command for upgrading a package):
sudo apt-get update && sudo apt-get upgrade mysql-server
3
After upgrading, you may still encounter the warning if existing schema elements use `UNSIGNED`. You will then need to follow Solution 1 to remove the `UNSIGNED` keyword from your schema.
🔗

Related Errors

5 related errors