PostgreSQL + diagrams.net Engineering Guide

Fixing Missing ALTER TABLE Foreign Keys in draw.io SQL Import

If you run pg_dump --schema-only on any production PostgreSQL database and paste the output into draw.io's Arrange → Insert → Advanced → SQL dialog, draw.io creates table boxes with 0 foreign key connector lines. Below is the exact 2-table reproduction, why it happens, and an embedded free converter that outputs true column-level tableRow connectors.

1. Minimal Reproducible PostgreSQL pg_dump DDL (2 Tables, 1 Foreign Key)

PostgreSQL's pg_dump intentionally emits all CREATE TABLE definitions first without inline REFERENCES clauses (so mutually referencing tables never fail load order), and appends every primary key and foreign key afterward using ALTER TABLE ONLY ... ADD CONSTRAINT ... FOREIGN KEY:

-- Minimal PostgreSQL pg_dump Foreign Key Repro (2 tables + 1 standalone ALTER TABLE ONLY FK)
-- Official draw.io "Insert -> SQL" and Moxie both import 2 tables and 0 foreign key edges.

SET statement_timeout = 0;
SELECT pg_catalog.set_config('search_path', '', false);

CREATE TABLE public.organizations (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    slug text NOT NULL,
    display_name text NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);

CREATE TABLE public.projects (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    organization_id uuid NOT NULL,
    name character varying(120) NOT NULL,
    region text DEFAULT 'us-east-1'::text NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);

ALTER TABLE ONLY public.organizations
    ADD CONSTRAINT organizations_pkey PRIMARY KEY (id);

ALTER TABLE ONLY public.projects
    ADD CONSTRAINT projects_pkey PRIMARY KEY (id);

ALTER TABLE ONLY public.projects
    ADD CONSTRAINT projects_organization_id_fkey
    FOREIGN KEY (organization_id) REFERENCES public.organizations(id) ON DELETE CASCADE;

2. Observed Result vs. Expected Column-Level .drawio Output

Tested against app.diagrams.net (v24.7.x Insert → Advanced → SQL) and the open Moxie SQL-to-draw.io converter using the exact 2-table DDL above:

draw.io Built-In "Insert → SQL": 2 Tables, 0 Foreign Key Edges
public.organizationsid uuidslug textdisplay_name textpublic.projectsid uuidorganization_id uuid (no edge!)name varchar(120)

Root cause: The built-in parser scans line-by-line inside CREATE TABLE (...) blocks and discards standalone ALTER TABLE [ONLY] statements completely — silently dropping both out-of-line PRIMARY KEY badges and every FOREIGN KEY connector.

ER Diagram Generator Output: Exact Column-to-Column tableRow Edge
organizationsPK id: uuid slug: text display_name: textprojectsPK id: uuidFK organization_id: uuid name: varchar(120)

How we fix it: Pass 1 indexes schemas, tables, columns, and ALTER TABLE ... PRIMARY KEY; Pass 2 binds inline REFERENCES, table-level FOREIGN KEY, and standalone ALTER TABLE [ONLY] constraints directly to shape=tableRow cell IDs.

3. One-Click Fix: Export Native .drawio Now (Free Up to 8 Tables)

Pre-loaded with the minimal reproduction above — click Export Editable .drawio or paste your own pg_dump --schema-only:

9–30 tables or v1→v2 layout-preserving diff? View Pricing

Local-First Privacy Guarantee: Database passwords, raw SQL, table/column names, and business notes stay in your browser; when you confirm export, the server receives only de-identified table relationship topology and bounding-box geometry to compute layout. Request body logging and session replay are disabled.

2 / 30 Tables(Free Tier)1 Foreign Key BoundSchemas: public
Free Tier: Up to 8 tables exports native editable .drawio immediately with no credit card.