Your Question
I have a user model for gorm that creates a query.
CREATE TABLE `users` (`id` uuid DEFAULT gen_random_uuid(),`first_name` text,`last_name` text,`display_name` text,`password` text,`email_verify_hash` text,`is_email_verified` numeric,`is_active` numeric,`is_profile_public` numeric,`email` text NOT NULL,`activated_at` datetime,`created_at` datetime,`updated_at` datetime,`alternate_email` text,PRIMARY KEY (`id`),CONSTRAINT `uni_users_id` UNIQUE (`id`),CONSTRAINT `uni_users_email` UNIQUE (`email`))
Gorm Model:-
type User struct {
ID uuid.UUID `gorm:"primaryKey;unique;type:uuid;default:gen_random_uuid()"` // Standard field for the primary key
FirstName string
LastName string
DisplayName string
Password string
EmailVerifyHash string
IsEmailVerified bool
IsActive bool
IsProfilePublic bool
Email string `gorm:"unique;not null"`
ActivatedAt time.Time
CreatedAt time.Time
UpdatedAt time.Time
AlternateEmail string
}
Its giving an error ERRO[0000] near "(": syntax error in sqlite db while automigrate the models.
The document you expected this should be explained
This model is automigrated to postgres gorm. But there is something off with sqlite part of gorm. I am using following go dependencies
gorm.io/driver/postgres v1.5.7
gorm.io/driver/sqlite v1.5.5
gorm.io/gorm v1.25.10
Expected answer
Please help me in this issue. Am I missing something in my implementation. Thanks in advance.
Comment From: puni9869
Can anyone help me in this...
Comment From: mkoziy
Try the following in your model. Worked for me.
ID uuid.UUID `gorm:"primaryKey;unique;type:uuid;default:(generate_random_uuid())"`
Comment From: puni9869
PS: I edited the ID
ID uuid.UUID
gorm:"primaryKey;unique;type:uuid;default:(gen_random_uuid())"// Standard field for the primary key
I changed to default:gen_random_uuid() to default:(gen_random_uuid())
Thanks everyone for helping me in this issue.