Common SQL Errors

MySQL Error 1861 (ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_NOT_NULL): cannot silently convert NULL values - Causes and Fixes

Galaxy Team
August 8, 2025

The ALTER TABLE statement failed because it tries to add or enforce a NOT NULL constraint while NULL data already exists and strict SQL mode forbids implicit conversion.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1861?

MySQL error 1861 (ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_NOT_NULL) occurs when ALTER TABLE attempts to add a NOT NULL column or make an existing column NOT NULL while rows still contain NULLs; clean or convert the data, then re-run the DDL to fix it.

Error Highlights

Typical Error Message

ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_NOT_NULL

Error Type

DDL Operation Error

Language

MySQL

Symbol

SQL_MODE ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_NOT_NULL was added in 5.7.1.

Error Code

1861

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 1861 (ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_NOT_NULL)?

Error 1861 fires when ALTER TABLE introduces a NOT NULL requirement that would turn existing NULL data into NOT NULL without an explicit value. From MySQL 5.7.1 onward, strict SQL mode blocks this silent conversion and raises the error instead of quietly replacing NULL with default values.

The message protects data quality by forcing you to fix or replace NULLs before tightening the constraint. Addressing it promptly avoids unexpected NULL handling and guarantees that new schema rules stay consistent.

When does error 1861 typically appear?

The error appears during DDL like ADD COLUMN ... NOT NULL, MODIFY COLUMN ... NOT NULL, or CHANGE COLUMN when the target table already stores at least one NULL in that column. It can also surface in online schema change tools or during replication if the replica enforces stricter sql_mode settings than the primary.

Why is resolving it important?

Leaving inconsistent NULL values prevents you from enforcing referential integrity, slows queries that rely on NOT NULL indexes, and blocks future schema migrations. Fixing the error guarantees clean datasets and predictable application behavior.

Common Causes

Existing NULL values in the column

Rows already contain NULL, and the ALTER statement tries to add a NOT NULL constraint or make the column NOT NULL.

Adding a new NOT NULL column without a DEFAULT

A column is added as NOT NULL but no default is provided, so MySQL cannot populate existing rows.

Strict SQL mode enabled

sql_mode includes STRICT_ALL_TABLES or STRICT_TRANS_TABLES, which disallows silent data changes that would otherwise convert NULL to default.

Mismatched replica sql_mode

Replication lag surfaces the error on a replica that runs stricter sql_mode than the source, even though the master accepted the change.

Related Errors

ERROR 1138: Invalid use of NULL value

Raised when an INSERT or UPDATE tries to put NULL into a NOT NULL column.

ERROR 1364: Field 'col' doesn't have a default value

Occurs during INSERT when NO DEFAULT exists for a NOT NULL column and strict mode is on.

ERROR 1263: Column set to default value; NULL supplied to NOT NULL column

Appears if strict mode is off and MySQL silently inserts default instead of NULL, the opposite of 1861 behavior.

FAQs

Can I bypass error 1861 by disabling strict mode?

Yes, but this only masks the problem. Data may become inconsistent. Cleanup NULLs instead.

Does error 1861 appear in MySQL 5.6 or earlier?

No. The condition was introduced in 5.7.1. Earlier versions silently converted NULLs.

Will adding a DEFAULT always stop the error?

Supplying a DEFAULT fixes new NOT NULL columns but will not solve NULLs already stored in existing columns.

How can Galaxy help prevent error 1861?

Galaxy flags NULL counts in schema diffs, suggests data cleanup queries, and lets teams review ALTER statements collaboratively to catch the issue before deployment.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo