1368
MariaDBerrorqueryhigh confidence

CHECK OPTION of view prevents this update

Production Risk

Low — DML fails; no data changed.

What this means

An INSERT or UPDATE on a view with a WITH CHECK OPTION would produce a row that the view's WHERE clause would not return, violating the check option.

Why it happens
  1. 1Inserting a row through a view that doesn't match the view's WHERE filter
  2. 2Updating a view row so the new value falls outside the view's WHERE filter
How to reproduce
trigger — this will error
trigger — this will error
CREATE VIEW active_users AS SELECT * FROM users WHERE active=1 WITH CHECK OPTION; INSERT INTO active_users (id, active) VALUES (99, 0);

expected output

ERROR 1368 (HY000): CHECK OPTION failed 'db.active_users'

Fix 1

Insert/update data that satisfies the view filter

Insert/update data that satisfies the view filter
INSERT INTO active_users (id, active) VALUES (99, 1);

Why this works

The row must match the view WHERE clause when WITH CHECK OPTION is set.

Fix 2

Insert directly into the base table

Insert directly into the base table
INSERT INTO users (id, active) VALUES (99, 0);

Why this works

Bypasses the CHECK OPTION constraint.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1368 ER_VIEW_NONUPD_CHECK

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors