How to Fix MySQL Error 1362 (ER_TRG_CANT_CHANGE_ROW)
You get mysql error 1362 when a database trigger tries to change a read-only row. You can fix this error by moving the row change into a before trigger. The database engine uses the symbol ER_TRG_CANT_CHANGE_ROW and SQLSTATE HY000 for this failure. The engine returns a clear message stating that updating the row is not allowed. When a developer writes a bad trigger, the engine blocks the write right away. This stop rule keeps table data safe from broken logic during a run. Why mysql error 136
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You get mysql error 1362 when a database trigger tries to change a read-only row. You can fix this error by moving the row change into a before trigger.
The database engine uses the symbol ER_TRG_CANT_CHANGE_ROW and SQLSTATE HY000 for this failure. The engine returns a clear message stating that updating the row is not allowed. When a developer writes a bad trigger, the engine blocks the write right away. This stop rule keeps table data safe from broken logic during a run.
Why mysql error 1362 happens in database triggers
Triggers run at set times during a table write event. A trigger can run before the database writes the row to the disk. A trigger can also run after the database finishes the write step. The database engine gives you two special row references inside a trigger body. One reference holds the old row data, and the other holds the new data.
In an after trigger, the database has already saved the new row data. It is too late to alter the new row values at that point. If your trigger tries to set a value on the new row, it fails. The database engine stops the action and throws mysql error 1362 to the client.
A second cause is trying to alter the old row reference. The old row shows the state of the data before the write started. Because it is past data, the database marks the old row as read-only. You cannot change the old row values in a before or after trigger. Any attempt to edit the old row will fail with the same error code.
How to find and fix the trigger failure
First, you need to check which trigger caused the failure in your database. Ask your team which table failed during the schema update or app deployment. You can read the system trigger view to inspect the trigger timing and body. Look for any line that assigns a value to a row reference.
Check if the trigger runs after an insert or update event on the table. If it is an after trigger, it cannot modify the incoming row values. To fix this, you must drop the trigger and recreate it. Set the new trigger to run before the insert or update event happens. Before triggers can change new row values before the engine saves the data.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Next, check if the trigger tries to change the old row reference. If it does, you must rewrite that part of the trigger logic. Change the statement so it updates the new row reference instead. Note that delete triggers only have an old row and no new row. You cannot change row values at all inside a delete trigger.
Safe ways to update triggers in production
Fixing triggers on a live database takes care and clear role rules. Dropping and creating a trigger can lock the table for a short time. You should test the new trigger in a staging setup before production. Run sample insert and update checks to make sure the logic works well.
Do not give developers broad admin rights to fix production triggers by hand. Instead, run the schema fix through a peer review step with full logging. Keep your trigger logic small so it does not slow down table writes. If a trigger masks sensitive fields like emails or phone numbers, check the output. Dynamic data masking can also rewrite card numbers or national IDs in query results.
Inspect every MySQL query and response in flight
Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.
First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.
Frequently asked questions
What does SQLSTATE HY000 mean with error 1362?
SQLSTATE HY000 is a general error class used by the database engine. You must read the specific code 1362 and symbol ER_TRG_CANT_CHANGE_ROW to find the trigger bug.
Can I change row values in an after trigger?
No, the database locks the new row values before an after trigger starts. You must use a before trigger if you need to change incoming column data.
Why can I not edit the old row in a before update trigger?
The old row holds the data that existed before the update began. The engine keeps it read-only so your trigger can compare past and new values.
Related guides
In this post