SQLSTATE 42703 ERROR Class 42: Syntax Error or Access Rule Violation

undefined_column column “…” referenced in foreign key constraint does not exist — 42703

PostgreSQL error "column "…" referenced in foreign key constraint does not exist" (SQLSTATE 42703): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A foreign key definition referenced a column that does not exist (on the referencing or referenced table). PostgreSQL raises SQLSTATE 42703 (undefined_column).

  • A column named in the FK clause is missing.
  • Common with a typo or wrong column name.
  • Affects both FOREIGN KEY and REFERENCES clauses.

What the server log shows

ERROR:  column "customer_id" referenced in foreign key constraint does not exist

Why PostgreSQL raises this — what the manual says

As Section 5.5.5 Foreign Keys explains:

A foreign key constrains and references specific named columns, so every column listed in the FOREIGN KEY or REFERENCES clause must already exist in the respective table; PostgreSQL rejects the constraint when a referenced column name cannot be found.

Defining a foreign key requires resolving each named column on both sides. When a referenced column name is not present in the table, PostgreSQL cannot build the constraint and reports 42703.

Common causes

  • A typo or wrong case in the FK column name.
  • Referencing a column that was renamed or never created.
  • Column order/name mismatch in a composite key.

How to fix it

  1. Verify the column names on both tables (\d tablename).
  2. Fix the name/case in the FOREIGN KEY/REFERENCES clause.
  3. Create the missing column before adding the constraint.

Related & next steps

Reference: PostgreSQL 18 Section 5.4 “Constraints”.

Was this helpful?