Skip to content

Ignore inline REFERENCES clauses to match MySQL #564

Open

Description

@JanJakes

MySQL accepts but ignores inline REFERENCES clauses. Our CREATE TABLE handling turns them into enforced foreign keys, so inserts that work in MySQL can fail with this driver.

Reproduction

CREATE TABLE p (id INT PRIMARY KEY);
CREATE TABLE t (id INT, a INT REFERENCES p (id));
INSERT INTO t (a) VALUES (999);

Expected: The insert succeeds. MySQL 8.4 ignores the inline reference and records no foreign-key constraint.

Actual: The insert fails with FOREIGN KEY constraint failed. The driver also creates foreign-key entries in KEY_COLUMN_USAGE and REFERENTIAL_CONSTRAINTS.

The equivalent single-column ALTER TABLE ADD and parenthesized ADD forms already ignore the inline clause and match MySQL.

Required behavior

  • Ignore inline REFERENCES during CREATE TABLE, including its foreign-key metadata.
  • Keep the same behavior across both ALTER TABLE ADD forms.
  • Preserve support for explicit table-level FOREIGN KEY (a) REFERENCES p (id) constraints.
  • Add regression coverage for the accepted insert and absent foreign-key metadata, alongside an explicit foreign-key constraint that still rejects the insert.

The MySQL documentation describes this distinction. Both the insert behavior and metadata difference were reproduced against MySQL 8.4.

Found while reviewing #557. These behaviors predate that PR and are separate from its parenthesized-list fix.

Related: #162.

Activity

  1. changed the title [-]Ignore inline REFERENCES clauses to match MySQL[/-] [+]Ignore inline `REFERENCES` clauses to match MySQL[/+] on Oct 23, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions