From ea4f6800524c0ed8aa246f7f5a68c11bcc19f593 Mon Sep 17 00:00:00 2001 From: anqiansong Date: Tue, 15 Jun 2021 18:54:41 +0800 Subject: [PATCH] Fix issue #747 (#765) Co-authored-by: anqiansong --- tools/goctl/model/sql/example/sql/user.sql | 4 ++-- tools/goctl/model/sql/parser/parser.go | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/goctl/model/sql/example/sql/user.sql b/tools/goctl/model/sql/example/sql/user.sql index 29fd6601..f33c097a 100644 --- a/tools/goctl/model/sql/example/sql/user.sql +++ b/tools/goctl/model/sql/example/sql/user.sql @@ -3,12 +3,12 @@ CREATE TABLE `user` ( `id` bigint(10) NOT NULL AUTO_INCREMENT, `user` varchar(50) NOT NULL DEFAULT '' COMMENT '用户', - `name` varchar(255) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '用户\t名称', + `name` varchar(255) COLLATE utf8mb4_general_ci NULL COMMENT '用户\t名称', `password` varchar(255) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '用户\n密码', `mobile` varchar(255) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '手机号', `gender` char(5) COLLATE utf8mb4_general_ci NOT NULL COMMENT '男|女|未公\r开', `nickname` varchar(255) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '用户昵称', - `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `create_time` timestamp NULL, `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `name_index` (`name`), diff --git a/tools/goctl/model/sql/parser/parser.go b/tools/goctl/model/sql/parser/parser.go index 09ed3f80..6654f487 100644 --- a/tools/goctl/model/sql/parser/parser.go +++ b/tools/goctl/model/sql/parser/parser.go @@ -170,9 +170,7 @@ func convertColumns(columns []*sqlparser.ColumnDefinition, primaryColumn string) if column.Type.NotNull { isDefaultNull = false } else { - if column.Type.Default == nil { - isDefaultNull = false - } else if string(column.Type.Default.Val) != "null" { + if column.Type.Default != nil { isDefaultNull = false } }