Maintaining Referential Integrity in Generated Data

Ensure foreign key relationships are preserved when generating synthetic data.

Overview

When generating data, TDK automatically maintains referential integrity across tables. This ensures that:

  • Foreign keys reference existing primary keys

  • Parent records are created before children

  • No orphaned records exist

  • Relationships remain valid

How It Works

TDK analyzes your database schema and generates data in dependency order:

# Parent table generated first
table_schema:
  - table_name_pattern: "public.customers"
    num_rows: 1000
    transformations:
      - columns: ["customer_id"]
        params:
          type: int_sequence_generator

# Child table references parent
  - table_name_pattern: "public.orders"
    num_rows: 5000
    transformations:
      - columns: ["customer_id"]
        params:
          type: foreign_key_generator
          referred_table: "customers"
          referred_schema: "public"
          referred_fields: ["customer_id"]