Your Question
I'm using gorm with sqlite3 which worked fine. Now I suddenly got the error data type mismatch, then I looked at the tables data type and one column has suddenly the data type int, instead of text it had earlier. Has something been changed or updated? I call on every startup AutoMigrate. Deleting the sqlite file and recreating it leads to the same behavior.
This is the declaration:
type Channel struct {
ChannelName string `json:"channelName" gorm:"primaryKey;not null;default:null"`
CreatedAt time.Time `json:"createdAt"`
}
The table info shows now:
sqlite> PRAGMA table_info([channels]);
0|channel_name|integer|1|null|1
2|created_at|datetime|0||0
Which it wasn't earlier. I was just text data type.
This might also be a sqlite3 bug, who knows.
Expected answer
Do I need to set the data type somehow different?
Comment From: li-jin-gou
@srad hello, I run code:
type Channel struct {
ChannelName string `json:"channelName" gorm:"primaryKey;not null;default:null"`
CreatedAt time.Time `json:"createdAt"`
}
func TestGORM(t *testing.T) {
DB.Migrator().CreateTable(&Channel{})
}
result:
[0.604ms] [rows:0] CREATE TABLE `channels` (`channel_name` text NOT NULL DEFAULT null,`created_at` datetime,PRIMARY KEY (`channel_name`))
--- PASS: TestGORM (0.00s)
it is normal.
can you provide gorm's version and driver's version ?