go-zero
go-zero copied to clipboard
gen model with field `create_at` causes field count not match
use ddl gen model with field create_at
causes field count not match
A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior, if applicable:
- The sql is
CREATE TABLE `login_history`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL DEFAULT 0 COMMENT 'ç¨æ·ID',
`login_ip` varchar(20) NOT NULL DEFAULT '' COMMENT 'ç»å½IP',
`login_time` timestamp NOT NULL COMMENT 'ç»å½æ¶é´',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'å建æ¶é´',
`update_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'æ´æ°æ¶é´',
PRIMARY KEY (`id`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
generated codes:
loginHistoryRowsExpectAutoSet = strings.Join(stringx.Remove(loginHistoryFieldNames, "`id`", "`create_time`", "`update_time`", "`create_at`", "`update_at`"), ",")
loginHistoryRowsWithPlaceHolder = strings.Join(stringx.Remove(loginHistoryFieldNames, "`id`", "`create_time`", "`update_time`", "`create_at`", "`update_at`"), "=?,") + "=?"
func (m *defaultLoginHistoryModel) Insert(ctx context.Context, data *LoginHistory) (sql.Result, error) {
loginHistoryIdKey := fmt.Sprintf("%s%v", cacheLoginHistoryIdPrefix, data.Id)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, loginHistoryRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.UserId, data.LoginIp, data.LoginTime, data.CreateAt, data.UpdateAt)
}, loginHistoryIdKey)
return ret, err
}
func (m *defaultLoginHistoryModel) Update(ctx context.Context, data *LoginHistory) error {
loginHistoryIdKey := fmt.Sprintf("%s%v", cacheLoginHistoryIdPrefix, data.Id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, loginHistoryRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, data.UserId, data.LoginIp, data.LoginTime, data.CreateAt, data.UpdateAt, data.Id)
}, loginHistoryIdKey)
return err
}
-
The error is
Error 1136: Column count doesn't match value count at row 1
More description Add any other context about the problem here.
env: go-ctl version 1.3.8
error log:
2022-06-08 15:32:09.781 ERROR sqlx/utils.go:139 stmt: insert into login_history
(user_id
,login_ip
,login_time
) values (1, '::1', 2022-06-08 15:32:09 +0800 CST, 0001-01-01 00:00:00 +0000 UTC, 0001-01-01 00:00:00 +0000 UTC), error: Error 1136: Column count doesn't match value count at row 1 {"trace": "0480f2901d6bd1ba416945661d914189", "span": "43a7a4e74556981d"}
update method has the same bug
It's a pity that is a known issue,I am considering to use sql builder to solve it on next release.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.