Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 枚举为空报错 #1727

Open
DG9Jww opened this issue May 5, 2024 · 0 comments
Open

[Bug]: 枚举为空报错 #1727

DG9Jww opened this issue May 5, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@DG9Jww
Copy link

DG9Jww commented May 5, 2024

gin-vue-admin 版本

2.6.3

Node 版本

v20.11.1

Golang 版本

go 1.22

是否依旧存在

可以

bug描述

1.自动化代码新增字段时,选择枚举,不写任何值

image

  1. 此时编译会报错
2024/05/06 02:39:25 D:/workspace/golang/src/gin-vue-admin/server/initialize/gorm.go:34 Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') COMMENT '',`img` varchar(191) COMMENT '',`meiju` enum('t1','t2','t3','t4') COM' at line 1
[0.503ms] [rows:0] CREATE TABLE `material` (`id` bigint unsigned AUTO_INCREMENT,`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL,`deleted_at` datetime(3) NULL,`status` boolean COMMENT '物料的启用状态',`test` enum() COMMENT '',`img` varchar(191) COMMENT '',`meiju` enum('t1','t2','t3','t4') COMMENT '',`created_by` bigint unsigned COMMENT '创建者',`updated_by` bigint unsigned COMMENT '更新者',`deleted_by` bigint unsigned COMMENT '删除者',PRIMARY KEY (`id`),INDEX `idx_material_deleted_at` (`deleted_at`))
[github.com/flipped-aurora/gin-vue-admin/server]2024/05/06 - 02:39:25.850     error   D:/workspace/golang/src/gin-vue-admin/server/initialize/gorm.go:59    register table failed   {"error": "Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') COMMENT '',`img` varchar(191) COMMENT '',`meiju` enum('t1','t2','t3','t4') COM' at line 1"}
  1. 此时生成mode里面的结构体字段如下:
 Test      string `json:"test" form:"test" gorm:"column:test;type:enum();comment:;"`                     //测试 

注意看 enum() ,这里导致的报错,解决方法在括号里面一对单引号即可 enum('')

修改建议

可增加判断是否为空,增加单引号,亦或改为必填,不能为空

@DG9Jww DG9Jww added the bug Something isn't working label May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants