[英]If the data type changes from string to bool data store is throwing an error
I am storing my struct values in google data store. 我将我的结构值存储在Google数据存储区中。 Here is my struct: 这是我的结构:
type Appointment struct {
ID string
Appointment Date string
Start Time string
End Time string
Select Specialization string
Smoking Status string
}
I have stored some data using datastore, but later changed the data type from string to bool for the field "Smoking Status" then the data store is throwing an error: 我已经使用数据存储存储了一些数据,但后来将“吸烟状态”字段的数据类型从字符串更改为bool,然后数据存储抛出错误:
{"error":{"message":"data store: cannot load field \\"Smoking Status\\" into a \\"simplysthealth.Encounter\\": type mismatch: string versus bool"}} {“错误”:{“消息”:“数据存储:无法将字段“吸烟状态”加载到“ simplysthealth.Encounter”中:类型不匹配:字符串与布尔值”}}
Is there any feasible solution for this? 有什么可行的解决方案吗?
package main
// I have corrected all of your method names
type Appointment struct {
ID string
AppointmentDate string
StartTime string
EndTime string
SelectSpecialization string
SmokingStatus string
}
type AllOldData struct {
Data []Appointment
}
type FixedAppointment struct {
ID string
AppointmentDate string
StartTime string
EndTime string
SelectSpecialization string
SmokingStatus bool
}
type FixedData struct {
Data []FixedAppointment
}
func TypeFixing() FixedData {
var OldData AllOldData
var NewData FixedData
OldData = GetYourAllOldData()
for i, v := range OldData.Data {
if v.SmokingStatus == "true" {
// other value exchanging
NewData.Data[i].SmokingStatus = true
} else {
// other value exchanging
NewData.Data[i].SmokingStatus = false
}
}
return NewData // Save the data in a new table or whatever you call it
}
func GetYourAllOldData() AllOldData {
// A function that returns all old data
return AllOldData{} // You must return return your all data
}
This is what you need to do it manually! 这是您需要手动执行的操作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.