diff --git a/pages/docs/create.md b/pages/docs/create.md index 9b18d0930f9..6ee44ce0a68 100644 --- a/pages/docs/create.md +++ b/pages/docs/create.md @@ -257,6 +257,32 @@ type User struct { } ``` +{% note warn %} +**NOTE** **SQLite** doesn't support some records are default values when batch insert. +See [SQLite Insert stmt](https://www.sqlite.org/lang_insert.html). For example: + +```go +type Pet struct { + Name string `gorm:"default:cat"` +} + +// In SQLite, this is not supported, so GORM will build a wrong SQL to raise error: +// INSERT INTO `pets` (`name`) VALUES ("dog"),(DEFAULT) RETURNING `name` +db.Create(&[]Pet{{Name: "dog"}, {}}) +``` +A viable alternative is to assign default value to fields in the hook, e.g. + +```go +func (p *Pet) BeforeCreate(tx *gorm.DB) (err error) { + if p.Name == "" { + p.Name = "cat" + } +} +``` + +You can see more info in [issues#6335](https://github.com/go-gorm/gorm/issues/6335) +{% endnote %} + When using virtual/generated value, you might need to disable its creating/updating permission, check out [Field-Level Permission](models.html#field_permission) ### Upsert / On Conflict