Open sin3degrees opened 3 weeks ago
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Dynamic struct autoIncrement ID problem in Create error '@id' field does not exist, statically compiled struct does not have this problem. As a temporary solution, the gorm tag is set autoIncrement:false, generates the ID with snowflake, and ensures that the corresponding database table ID is not set to increment. I use the goja library to call the go function, and js class can only turn the dynamic structure, in order to let js use gorm, using the specified table name of the dynamic structure scheme, playground is not convenient to repeat the problem, which the call process is relatively complex. 动态结构体自增 ID 在 Create 时报错’@id’字段不存在的问题,静态编译的结构体没这个问题。临时解决方案,gorm 标签设置 autoIncrement:false,用 snowflake 生成 ID,并且保证对应的数据库表的 ID 不设置自增。 本人使用 goja 库调用 go 函数,而 js类只能转动态结构体,为了让 js 使用 gorm,采用了指定表名的动态结构体方案,playgroud 不方便复现问题,其中的调用过程相对复杂。