Diagnostic Queries
Symptoms
A CREATE TRIGGER tried to create a trigger whose name already exists on the relation. PostgreSQL raises SQLSTATE 42710 (duplicate_object).
- A trigger with that name already exists on the table.
- Trigger names are unique per relation.
- Common in re-run migrations.
What the server log shows
ERROR: trigger "audit_orders" for relation "orders" already exists
Why PostgreSQL raises this — what the manual says
As the CREATE TRIGGER reference (Description) explains:
A trigger of that name already exists on the table; trigger names are local to a table, so each must be unique per table — drop or rename the existing trigger, or use CREATE OR REPLACE TRIGGER.
Trigger names are unique within a relation. Creating one whose name is already present collides with the existing trigger, so PostgreSQL reports 42710.
Common causes
- Re-running a migration that creates the trigger.
- Two triggers sharing a name on the same table.
- Forgetting to drop the prior trigger before recreating.
How to fix it
- Use
CREATE OR REPLACE TRIGGERto redefine it (PG14+). DROP TRIGGER IF EXISTS … ON tablebefore recreating.- Choose a unique trigger name.
Related & next steps
Reference: PostgreSQL 18 — CREATE TRIGGER.
Thanks — noted. This helps keep the database accurate.