How AI is applied across API Evangelist and APIs.io. Read my AI disclosure →
API Evangelist API Evangelist
Discovery
Learnings
Guidance
Toolbox
Alignment
API Evangelist LLC

Seeding Postgres When Your Schema Has Foreign-Key Cycles

calendar_today July 17, 2026 person Mikhail Shytsko domain dzone

I have lost more afternoons than I would like to admit on this exact problem: a seed script that ran cleanly yesterday now crashes on its first INSERT , and the error message tells you something you already knew, namely that you have a chicken-and-egg dependency between two tables. SQL ERROR: insert or update on table “users” violates foreign key constraint “users_organization_id_fkey” DETAIL: Key (organization_id)=(1) is not present in table “organizations”. The natural next move is to reorder the inserts, putting organizations first, except that organizations.owner_user_id is NOT NULL REFERE

open_in_new Read original post