gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.8k stars 1.61k forks source link

During the connection process, if a table field has been added, it is not possible to update the newly added field's data using g.Model(tableName).Data(newData).Update(). #3654

Closed leavky closed 5 months ago

leavky commented 5 months ago

Go version

go1.21.5

GoFrame version

v2.7.0

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

开启服务,使用ALTER TABLE tableName ADD COLUMN fieldName TEXT; 为表格添加一个新的字段,然后通过g.Model(tableName ).Where("id", recordId).OmitEmpty().Data(newData).Update() 无法更新数据,但是新增字段后重启服务,使用g.Model(tableName ).Where("id", recordId).OmitEmpty().Data(newData).Update() 就可以更新数据了

What did you see happen?

通过g.Model(tableName ).Where("id", recordId).OmitEmpty().Data(newData).Update() 无法更新数据

What did you expect to see?

新增字段后可以通过通过g.Model(tableName ).Where("id", recordId).OmitEmpty().Data(newData).Update() 更新数据,目前使用执行SQL语句解决了,希望可以修正一下在运行过程中增加了字段也可以更新数据

oldme-git commented 5 months ago

g.Model() 是一个单例对象,并只会初始化一次 DB 对象,所以这并不是一个 Bug。如果你想在更新字段后操作数据库,可以自行维护一个 gdb 对象

Issues-translate-bot commented 5 months ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


g.Model() is a singleton object and will only initialize the DB object once, so this is not a Bug. If you want to operate the database after updating the fields, you can maintain a gdb object yourself