Skip to content

Fix primary key detection for column-level constraints (go-zero issue #4967)#10

Open
aburizalpurnama wants to merge 2 commits into
zeromicro:mainfrom
aburizalpurnama:main
Open

Fix primary key detection for column-level constraints (go-zero issue #4967)#10
aburizalpurnama wants to merge 2 commits into
zeromicro:mainfrom
aburizalpurnama:main

Conversation

@aburizalpurnama
Copy link
Copy Markdown

Description

This PR fixes an issue where model generation fails with the error "missing primary key" when the primary key is defined using column-level constraints instead of table-level constraints.

Problem

Currently, ddl-parser only detects primary keys defined at the table level, which causes it to miss valid primary key definitions that are declared at the column level.

Solution

  • Updated the primary key detection logic to also include column-level primary key definitions.
  • Ensures compatibility with more SQL schema styles.

Testing

  • Added unit tests to verify both table-level and column-level primary key detection.
  • Confirmed model generation now works correctly with column-level constraints.

Related Issue

Fixes #9

@aburizalpurnama aburizalpurnama changed the title Fix primary key detection for column-level constraints Fix primary key detection for column-level constraints (go-zero issue #4967) Jun 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"goctl model mysql ddl" command generates code reports "missing primary key"

1 participant