Skip to content

[P1][bug] No type-compatibility check between FK local column and referenced column — invalid FK slips through to save #385

Closed

Description

@EVWorth

Context

Table Designer Foreign Keys tab.

Problem

src/components/designer/TableDesigner.tsx:720-790 — the FK editor lets the user pick any local column and any referenced column with no type check. MySQL enforces type compatibility at ALTER TABLE … ADD FOREIGN KEY time — INT REFERENCES VARCHAR(50) raises ERROR 1215 (HY000): Cannot add foreign key constraint. The error surfaces at Save but the user has no pre-flight check. The loadRefTableColumns helper (line 121-132) only fetches column names; types are not loaded.

Files

  • src/components/designer/TableDesigner.tsx:121-132 (loadRefTableColumns)
  • src/components/designer/TableDesigner.tsx:720-790 (ForeignKeysTab)

Repro

  1. Create users (id INT, email VARCHAR(50))
  2. Create orders (id INT, user_email VARCHAR(50))
  3. Table Designer on orders, add FK (user_email → users.email)
  4. Wait — that's compatible. Try: (user_email → users.id) — INT/VARCHAR mismatch
  5. Click Apply Changes — MySQL returns error 1215

Expected

FK creation with mismatched types shows an inline warning before save. Same-family FK creation succeeds without warning.

Proposed fix

Extend loadRefTableColumns to return Record<string, ColumnInfo[]> (or Record<string, Map<name, type>>) instead of Record<string, string[]>. Compare local column type against referenced column type after normalising: VARCHAR(255) compatible with VARCHAR(50) (same family); INT with BIGINT (target bigger); TEXT with VARCHAR is not. Show an inline warning if mismatched, but allow the user to proceed. Scope: S.

Acceptance

FK creation with mismatched types shows an inline warning before save. Same-family FK creation succeeds without warning.

Needs human verify

no

Doc drift

no

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/designer
    on Jul 31, 2026
  2. added a commit that references this issue on Sep 7, 2026
    72f3e55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/designerauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions