beego / bee

Bee is a tool for helping develop with beego app framework.
Apache License 2.0
1.44k stars 920 forks source link

bee generate appcode error #799

Closed michaelshow closed 2 years ago

michaelshow commented 3 years ago

exclude:
bee generate appcode -tables="md_books" -conn="root:password@tcp(127.0.0.1:3306)/mindoc"

The following error occurred: `__ | \ | |/ / __ | \ / \ / \ | |/ /| /| / ___/ \| ___| v1.12.0 2021/08/27 18:12:57 INFO ▶ 0001 Using 'mysql' as 'SQLDriver' 2021/08/27 18:12:57 INFO ▶ 0002 Using 'root:password@tcp(127.0.0.1:3306)/mindoc' as 'SQLConn' 2021/08/27 18:12:57 INFO ▶ 0003 Using 'md_books' as 'Tables' 2021/08/27 18:12:57 INFO ▶ 0004 Using '3' as 'Level' 2021/08/27 18:12:57 INFO ▶ 0005 Analyzing database tables... panic: runtime error: index out of range [2] with length 0

goroutine 1 [running]: github.com/beego/bee/generate.extractIntSignness(0xc00020892a, 0x3, 0xc000208930, 0xc) E:/xzf/project-git/git-2/pkg/mod/github.com/beego/bee@v1.12.3/generate/g_appcode.go:930 +0xcd github.com/beego/bee/generate.(*MysqlDB).GetColumns(0x1221c68, 0xc00024e270, 0xc00020a360, 0xc0002049f0) E:/xzf/project-git/git-2/pkg/mod/github.com/beego/bee@v1.12.3/generate/g_appcode.go:481 +0xfc9 github.com/beego/bee/generate.getTableObjects(0xc000200540, 0x1, 0x1, 0xc00024e270, 0xdaa850, 0x1221c68, 0x0, 0x1, 0xc000200450) E:/xzf/project-git/git-2/pkg/mod/github.com/beego/bee@v1.12.3/generate/g_appcode.go:363 +0x1e9 github.com/beego/bee/generate.gen(0xc0002086d2, 0x5, 0xc000214720, 0x2a, 0xc000139d07, 0xc000139ce0, 0xc000214600, 0x20) E:/xzf/project-git/git-2/pkg/mod/github.com/beego/bee@v1.12.3/generate/g_appcode.go:316 +0x2fc github.com/beego/bee/generate.GenerateAppcode(0xc0002086d2, 0x5, 0xc000214720, 0x2a, 0x1182c38, 0x1, 0xc0002086d8, 0x8, 0xc000214600, 0x20) E:/xzf/project-git/git-2/pkg/mod/github.com/beego/bee@v1.12.3/generate/g_appcode.go:295 +0x232 github.com/beego/bee/cmd/commands/generate.appCode(0x11bb0a0, 0xc00013e020, 0x3, 0x6, 0xc000214600, 0x20) E:/xzf/project-git/git-2/pkg/mod/github.com/beego/bee@v1.12.3/cmd/commands/generate/generate.go:158 +0x653 github.com/beego/bee/cmd/commands/generate.GenerateCode(0x11bb0a0, 0xc00013e020, 0x3, 0x6, 0x0) E:/xzf/project-git/git-2/pkg/mod/github.com/beego/bee@v1.12.3/cmd/commands/generate/generate.go:91 +0x288 main.main() E:/xzf/project-git/git-2/pkg/mod/github.com/beego/bee@v1.12.3/main.go:61 +0x297 `

flycash commented 3 years ago

It seems that Bee is not able to fetch the database schema. Could you please provide your table schema so that I can reproduce this issue.

michaelshow commented 3 years ago

This is the sql file of my table:md_books. but the sql file cannot upload:

` /* Navicat MySQL Data Transfer

Source Server : localhost Source Server Type : MySQL Source Server Version : 80026 Source Host : localhost:3306 Source Schema : mindoc

Target Server Type : MySQL Target Server Version : 80026 File Encoding : 65001

Date: 03/09/2021 10:04:10 */

SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0;


-- Table structure for md_books


DROP TABLE IF EXISTS md_books; CREATE TABLE md_books ( book_id int(0) NOT NULL AUTO_INCREMENT, book_name varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '', item_id int(0) NOT NULL DEFAULT 1, identify varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '', auto_release int(0) NOT NULL DEFAULT 0, is_download int(0) NOT NULL DEFAULT 0, order_index int(0) NOT NULL DEFAULT 0, description varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '', publisher varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '', label varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '', privately_owned int(0) NOT NULL DEFAULT 0, private_token varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL, book_password varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL, status int(0) NOT NULL DEFAULT 0, editor varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '', doc_count int(0) NOT NULL DEFAULT 0, comment_status varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'open', comment_count int(0) NOT NULL DEFAULT 0, cover varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '', theme varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'default', create_time datetime(0) NOT NULL, history_count int(0) NOT NULL DEFAULT 0, is_enable_share int(0) NOT NULL DEFAULT 0, member_id int(0) NOT NULL DEFAULT 0, modify_time datetime(0) NULL DEFAULT NULL, version bigint(0) NOT NULL DEFAULT 0, is_use_first_document int(0) NOT NULL DEFAULT 0, auto_save int(0) NOT NULL DEFAULT 0, PRIMARY KEY (book_id) USING BTREE, UNIQUE INDEX identify(identify) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;


-- Records of md_books


INSERT INTO md_books VALUES (1, 'MinDoc演示项目', 1, 'mindoc', 0, 0, 0, '这是一个MinDoc演示项目,该项目是由系统初始化时自动创建。', '', '', 0, '', '', 0, 'markdown', 1, 'closed', 0, '/static/images/book.jpg', 'default', '2021-08-26 17:14:23', 0, 0, 1, '2021-08-26 17:14:23', 1629969262, 0, 0);

SET FOREIGN_KEY_CHECKS = 1;

`

flycash commented 2 years ago

Sorry I cannot reproduce this problem, here is my log: image