Open puni9869 opened 2 months ago
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.
ERRO[0000] near "(": syntax error
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
Please help me in this issue. Am I missing something in my implementation. Thanks in advance.
Can anyone help me in this...
Try the following in your model. Worked for me.
ID uuid.UUID `gorm:"primaryKey;unique;type:uuid;default:(generate_random_uuid())"`
Your Question
I have a user model for gorm that creates a query.
Gorm Model:-
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
Expected answer
Please help me in this issue. Am I missing something in my implementation. Thanks in advance.