Skip to content

gen by ddl occur panic  #4503

@xieyj-apple

Description

@xieyj-apple

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The code is

    CREATE TABLE user (
       id bigint AUTO_INCREMENT,
       dept_id bigint not null DEFAULT 0 COMMENT 'dept id',
       name varchar(255) NULL COMMENT 'The username',
       password varchar(255) NOT NULL DEFAULT '' COMMENT 'The user password',
       mobile varchar(255) NOT NULL DEFAULT '' COMMENT 'The mobile phone number',
       gender char(10) NOT NULL DEFAULT 'male' COMMENT 'gender,male|female|unknown',
       nickname varchar(255) NULL DEFAULT '' COMMENT 'The nickname',
       type tinyint(1) NULL DEFAULT 0 COMMENT 'The user type, 0:normal,1:vip, for test golang keyword',
       create_at timestamp NULL,
       update_at timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
       UNIQUE mobile_index (mobile),
       UNIQUE dept_name_index (dept, name),
       PRIMARY KEY (id)

) ENGINE = InnoDB COLLATE utf8mb4_general_ci COMMENT 'user table';


2. The error is

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x10 pc=0x1b01883]

goroutine 1 [running]:
github.com/zeromicro/go-zero/tools/goctl/model/sql/parser.checkDuplicateUniqueIndex(0xc00064f310?, {0xc000c75480, 0x4})
/github/workspace/tools/goctl/model/sql/parser/parser.go:182 +0x323
github.com/zeromicro/go-zero/tools/goctl/model/sql/parser.Parse({0xc000423080, 0x3e}, {0x0, 0x0}, 0x20?)


**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environments (please complete the following information):**
- OS: [e.g. Linux]
- go-zero version [e.g. 1.2.1]
- goctl version [e.g. 1.2.1, optional]

**More description**
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

area/goctlCategorizes issue or PR as related to goctl.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions