GORM Playground Link
Description
create table business_t (
id INTEGER PRIMARY KEY AUTOINCREMENT,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
deleted_at TIMESTAMP DEFAULT NULL,
name TEXT NOT NULL
);
type BusinessModel struct {
ID int32 `gorm:"column:id;primaryKey" json:"id"`
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;default:NULL" json:"deleted_at"`
Name string `gorm:"column:name;not null" json:"name"`
}
// var models = []*BusinessModel
// models数据赋值,DeletedAt不赋值.
ret := tx.Clauses(clause.OnConflict{
UpdateAll: true,
}).Create(models)
错误信息
near "DEFAULT": syntax error
INSERT INTO `business_t` (`created_at`,`updated_at`,`name`,`deleted_at`,`id`) VALUES ("2022-10-22 18:14:26.477","2022-10-22 18:14:26.477","Biz-1",DEFAULT,3)
在Sqlite中,填充默认值的关键字应该是NULL,不是DEFAULT。
依赖: github.com/mattn/go-sqlite3 v1.14.15 gorm.io/gorm v1.24.0
Comment From: github-actions[bot]
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 ✨
Comment From: a631807682
It work for gorm.io/driver/sqlite, gorm.DeletedAt is the implementation of gorm itself, if you use a driver other than gorm, you need to support it yourself.
Comment From: bin-liu
@a631807682 emm. I'm using gorm.io/driver/sqlite v1.4.3 gorm.io/driver/sqlite is depends on github.com/mattn/go-sqlite3
Comment From: a631807682
@bin-liu Can you reproduce in https://github.com/go-gorm/playground ?