Common SQL Errors

MySQL Error 1363: ER_TRG_NO_SUCH_ROW_IN_TRG - How to Fix and Prevent

Galaxy Team
August 6, 2025

<p>The trigger tries to access OLD or NEW row data that is not available at its timing, causing execution to stop.</p>

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 1363 ER_TRG_NO_SUCH_ROW_IN_TRG?

<p>MySQL Error 1363 ER_TRG_NO_SUCH_ROW_IN_TRG happens when a trigger references OLD or NEW rows in a timing where they do not exist, such as OLD in BEFORE INSERT. Remove the invalid reference or adjust the trigger timing to resolve the issue.</p>

Error Highlights

Typical Error Message

There is no %s row in %s trigger

Error Type

Trigger Logic Error

Language

MySQL

Symbol

ER_TRG_NO_SUCH_ROW_IN_TRG

Error Code

1363

SQL State

HY000

Explanation

Table of Contents

What does MySQL Error 1363 mean?

Error 1363 occurs when a trigger body references OLD or NEW pseudorecords that are unavailable in the trigger timing. MySQL raises the error and aborts the statement.

For example, referencing OLD.column in a BEFORE INSERT trigger fails because the OLD row is undefined prior to insert. Likewise, NEW.column is unavailable in an AFTER DELETE trigger.

When does this error appear most often?

The error is common during trigger creation or table alteration. It also shows up at runtime if a trigger definition was edited incorrectly or copied from another timing without updating row references.

Developers usually encounter it while migrating databases, refactoring audit triggers, or implementing soft-delete logic.

Why is it critical to fix?

Unresolved, the error prevents DML operations on the table, blocking application workflows. Fixing it restores data integrity and system availability.

What Causes This Error?

Using OLD in BEFORE INSERT or NEW in AFTER DELETE triggers triggers the error because the required record version does not exist.

Attempting to reference OLD in BEFORE UPDATE on columns defined as generated or virtual can also cause the issue if the engine cannot supply the old value.

How to Fix MySQL Error 1363 ER_TRG_NO_SUCH_ROW_IN_TRG

Identify the invalid OLD or NEW reference, then adjust the trigger timing or remove the reference. Re-create the trigger with correct logic and test.

Optionally, split logic across multiple triggers so each uses only valid pseudorecords.

Common Scenarios and Solutions

Audit columns often need NEW values in BEFORE INSERT. Move audit logic requiring OLD values to BEFORE UPDATE to avoid the error.

Soft-delete implementations may require OLD data in AFTER DELETE. Ensure the trigger timing matches the required row version.

Best Practices to Avoid This Error

Review MySQL documentation on which pseudorecords are available in each trigger timing before writing triggers.

Write unit tests executing INSERT, UPDATE, and DELETE to catch invalid row references early. Version triggers in a shared SQL repository like Galaxy to track safe changes.

Related Errors and Solutions

Error 1235 This version of MySQL does not yet support triggers on both tables in same time event - occurs when conflicting triggers exist. Remove duplicates.

Error 1442 Can't update table in stored function/trigger because it is already in use - avoid self-referencing writes inside triggers.

Common Causes

Cause: Incorrect Trigger Timing

Referencing OLD in BEFORE INSERT or NEW in AFTER DELETE when the corresponding row does not exist.

Cause: Copy-Paste Oversight

Developers duplicate a trigger for another timing but forget to alter row references appropriately.

Cause: Schema Refactor

Columns renamed or dropped cause outdated OLD or NEW references inside triggers.

Cause: Version Mismatch

Older MySQL versions may not support certain virtual column references, leading to missing row data.

Related Errors

Error 1442 Cannot modify table used in trigger

Occurs when a trigger tries to update the same table it fires on, causing recursion. Use intermediate tables or AFTER triggers.

Error 1235 Trigger already exists for event

Raised when multiple triggers are defined for the same table, timing, and event in MySQL versions prior to 5.7. Modify or merge triggers.

Error 1146 Table does not exist

Appears when a trigger references a table that was dropped or renamed. Update the trigger definition.

FAQs

Can I use OLD in BEFORE INSERT?

No. The OLD pseudorecord is only available in UPDATE and DELETE triggers because there is no previous row during an INSERT.

Why does AFTER DELETE not allow NEW values?

NEW represents the post-change row image, which does not exist after a DELETE. Use OLD instead.

How do I debug trigger errors quickly?

Enable the general log temporarily, reproduce the error, and examine the failing statement along with trigger definitions.

Does Galaxy help prevent trigger mistakes?

Yes. Galaxy highlights invalid OLD and NEW references during trigger editing and allows version control so teams can review changes 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