You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the goctl model command to generate Go code for PostgreSQL, the auto-increment primary key cannot be null, and passing a 0 value does not trigger auto-incrementation.
#4565
Open
SanJan-Loe opened this issue
Jan 13, 2025
· 1 comment
Describe the bug
当使用gotcl 工具,将pgsql sql文件转化为go的model代码时,的auto_increment特征导致,生成的值为int64,而不是sql.NULLINT64,调用默认生成的Insert函数时,传入的 To Reproduce
Steps to reproduce the behavior, if applicable:
The code is
对应的sql代码:
"registration_order" BIGINT UNIQUE GENERATED BY DEFAULT AS IDENTITY
If you want sql.NULLINT64 instead of int64, you should see the document and try it again.
The error log maybe cause by your constraint incorrect, pls take a check, it's not cause by goctl.
kevwan
changed the title
goctl model指令生成pgsql 的go代码时自增主键不能为空,传0值无法自增
When using the goctl model command to generate Go code for PostgreSQL, the auto-increment primary key cannot be null, and passing a 0 value does not trigger auto-incrementation.
Jan 17, 2025
Describe the bug
当使用gotcl 工具,将pgsql sql文件转化为go的model代码时,的auto_increment特征导致,生成的值为int64,而不是sql.NULLINT64,调用默认生成的Insert函数时,传入的
To Reproduce
Steps to reproduce the behavior, if applicable:
对应的sql代码:
生成的go model代码
RegistrationOrder int64
db:"registration_order"
对应的Insert代码:
func (m *defaultUserModel) Insert(ctx context.Context, data *User) (sql.Result, error) {
publicUserAccountKey := fmt.Sprintf("%s%v", cachePublicUserAccountPrefix, data.Account)
publicUserEmailKey := fmt.Sprintf("%s%v", cachePublicUserEmailPrefix, data.Email)
publicUserExtendidKey := fmt.Sprintf("%s%v", cachePublicUserExtendidPrefix, data.Extendid)
publicUserGsucidKey := fmt.Sprintf("%s%v", cachePublicUserGsucidPrefix, data.Gsucid)
publicUserIdKey := fmt.Sprintf("%s%v", cachePublicUserIdPrefix, data.Id)
publicUserPhonenumberKey := fmt.Sprintf("%s%v", cachePublicUserPhonenumberPrefix, data.Phonenumber)
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 ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)", m.table, userRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Id, data.Extendid, data.Gsucid, data.Name, data.Account, data.Password, data.Email, data.Phonenumber, data.Status, data.Errorlogincount, data.Refreshtoken, data.RegistrationOrder, data.Lastlogintime, data.Createtime, data.Updatetime, data.Deletetime)
}, publicUserAccountKey, publicUserEmailKey, publicUserExtendidKey, publicUserGsucidKey, publicUserIdKey, publicUserPhonenumberKey)
return ret, err
}
默认重复插入registration_order为0的数据时,出现如下错误:
error in inserting user:pq: duplicate key value violates unique constraint "user_registration_order_key"
The text was updated successfully, but these errors were encountered: