Unknown column 'users.deleted_at' in 'where clause' using gorm


(Tanweer Shahzaad) #1

How do I stop gorm from complaining about deleted_at field. I know I can plain struct without gorm.Model but that would mean I cant add relations to user/other structs… eg I cannot declare user has one language association in User struct if I dont add gorm.Model but if I add, it would complain about deleted_about field which of course doesnt exist. any help is really appreciated. I have tried some combination of tags eg I added DeletedAt field and give it tags 1. gorm: “-” and then I also tried json: “-” to ignore it, but still no luck
This seems very small basic but I couldnt figure sorry I am newbie in golang.


(Vivek) #2

If you want to add relation to other structs like a foreign key constraint you can do this using foreign key tag in gorm. What relation do you want to add between two different structs?


(Tanweer Shahzaad) #3

Thank you for your reply. I found my answer in the conventions of gorm docs

I’ve just created my own base model instead using gorm.Model and didnt use deleted_at field on it. And it worked perfectly.

Edit:
And seems that I was wrong, I can have any base struct and associations will work. Just dont user gorm.Model as base Model.