How to Fix MySQL Error 1363 (ER_TRG_NO_SUCH_ROW_IN_TRG)
You get mysql error 1363 when a database trigger tries to read a row state that does not exist. You can fix this error by matching the row prefix to the right trigger action. MySQL maps this issue to the symbol ER_TRG_NO_SUCH_ROW_IN_TRG and the general SQLSTATE code HY000. The database sends a message saying there is no old or new row in the trigger. When this happens, the database stops your schema change right away. Your app stays safe, as the engine blocks bad trigger logic before it can run
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 1363 when a database trigger tries to read a row state that does not exist. You can fix this error by matching the row prefix to the right trigger action.
MySQL maps this issue to the symbol ER_TRG_NO_SUCH_ROW_IN_TRG and the general SQLSTATE code HY000. The database sends a message saying there is no old or new row in the trigger. When this happens, the database stops your schema change right away. Your app stays safe, as the engine blocks bad trigger logic before it can run.
What causes mysql error 1363 in database triggers
Database triggers let your team run rules when table rows change. You can set up a trigger to run on insert, update, or delete events. Inside the trigger body, you point to column values using old or new row prefixes.
Still, not every table event has both row states available. An insert event adds fresh data, so no old row state exists before the insert. If your insert trigger points to an old column value, MySQL throws mysql error 1363.
A delete event removes data that is already in the table. Because the row is leaving the table, there is no new row state after the delete. If your delete trigger points to a new column value, the engine rejects the rule.
Only update events give you both old and new row states at the same time. During an update, the old state holds data from before the write. The new state holds the fresh data that your app sends to the table. Mixing up these states during schema migrations is the main cause of this error.
How to diagnose and fix the trigger failure safely
To find the broken rule, check the exact error text in your deployment log. The message tells you which row prefix failed and which trigger event caused the problem. Look at the migration file that failed to run during your release.
Check the event type at the top of your trigger definition. If the rule runs on insert, replace every old row reference with the new prefix. Make sure the logic matches what should happen when a brand new row arrives.
Just-in-Time Access + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
If the rule runs on delete, replace every new row reference with the old prefix. This lets your trigger read the values that are about to leave the table. You can then write those old values to an audit log table without errors.
Sometimes a developer picks the wrong event type by mistake when writing the script. For example, they might write a delete trigger when they meant to write an update rule. In that case, change the trigger event to update instead of changing the prefixes.
How to prevent trigger errors in production
Fixing a trigger in a live database takes care and strict role rules. Never grant wide admin rights to every engineer just to fix a broken migration script. Wide permissions make it easy for someone to drop the wrong trigger on a live table.
Instead, test all schema scripts in a staging database before you run them in production. A quick test run catches ER_TRG_NO_SUCH_ROW_IN_TRG right away because the engine checks syntax at creation time. You do not even need to insert test data to see this specific error.
When you are ready to fix production, use a peer review workflow for the schema change. Have a second engineer check the trigger event type and every row prefix in the script. Keep your audit logs turned on so you have a clear record of every schema fix. Also, use data masking to rewrite matched fields like emails or card numbers in query results.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.
Frequently asked questions
Does mysql error 1363 happen when the trigger runs or when you create it?
MySQL catches this error when you try to create the trigger. The database checks the row prefixes against the trigger event before saving the rule. It will not let you save a broken trigger into the schema.
Can I use both old and new row references in the same MySQL trigger?
Yes, you can use both prefixes inside an update trigger. An update event has the old data before the change and the new data after. Insert and delete triggers only support one row state each.
What do ER_TRG_NO_SUCH_ROW_IN_TRG and SQLSTATE HY000 mean?
ER_TRG_NO_SUCH_ROW_IN_TRG is the internal MySQL symbol for error code 1363. SQLSTATE HY000 is a general error code used for rules that do not fit standard categories. Together, they tell your client app that a trigger points to a missing row state.
Related guides
In this post