gormt
gormt copied to clipboard
自增字段tag缺失,迁移后,创建的表无自增属性,导致执行sql失败
数据表中的主键是自增的,生成go文件后,tag中未包含自增的描述autoIncrement
ID uint32 `gorm:"primaryKey;column:id;type:int unsigned;not null"`
当执行db. AutoMigrate
后,插入一条数据会报错:
Could not save row: Error 1364: Field 'id' doesn't have a default value
gorm迁移的sql语句是:
CREATE TABLE `rank` (`id` int unsigned NOT NULL,PRIMARY KEY (`id`))
解决方案:在生成go文件的时候,把是否自增的信息写进tag中。
详细tag参考:https://gorm.io/zh_CN/docs/models.html#%E5%AD%97%E6%AE%B5%E6%A0%87%E7%AD%BE
经过了解,这是两个bug:
- gormt没有把autoIncrement写进tag中(不过,该实现还是要实现的吧~
- gorm没有实现autoIncrement (参考:https://github.com/go-gorm/gorm/issues/5266
好的,收到
我提交gorm的修复pr没有被接受,因为改动不兼容其他的db。。。 放弃提交了。。。
更新了下,请查看,未测试 https://github.com/xxjwxc/gormt/commit/fc112a736bddaf8e66dc149381d163b19a0794ff
我提交gorm的修复pr没有被接受,因为改动不兼容其他的db。。。 放弃提交了。。。
我没有看到你的pr
我给关了。。。 https://github.com/go-gorm/gorm/pull/5452
这:https://github.com/xxjwxc/gormt/commit/3dea08f1e40f0e6db6a4a393551e94d5beb1d0ec gormt : gorm tools