From b818726b1bcdc33a488a8531f9b142566516761b Mon Sep 17 00:00:00 2001 From: Mohammad Mahdi Date: Fri, 25 Jul 2025 12:15:44 +0330 Subject: [PATCH] Fix mysql Foreign key constraint error --- internal/domain/post.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/domain/post.go b/internal/domain/post.go index b324926..aa5d6ea 100644 --- a/internal/domain/post.go +++ b/internal/domain/post.go @@ -5,11 +5,11 @@ type Post struct { Url string `json:"url"` AccountID string // Foreign key field (must match Account.AccId) Account Account `json:"account" gorm:"foreignKey:AccountID;references:AccId"` - Attachments []MediaAttachment `json:"media_attachments" gorm:"foreignKey:PostID;references:ID"` + Attachments []MediaAttachment `json:"media_attachments" gorm:"foreignKey:PostID;references:ID"` } type Account struct { - AccId string `json:"id" gorm:"primaryKey;index"` + AccId string `json:"id" gorm:"primaryKey;column:acc_id;type:varchar(19);index"` Username string `json:"username"` Acct string `json:"acct"` DisplayName string `json:"display_name"` @@ -19,12 +19,12 @@ type Account struct { } type MediaAttachment struct { - ID string `json:"id" gorm:"primaryKey"` + ID string `json:"id" gorm:"primaryKey;type:varchar(19)"` Type string `json:"type"` Url string `json:"url"` PreviewUrl string `json:"preview_url"` RemoteUrl string `json:"remote_url"` - PostID string `gorm:"index:idx_post_approved,post_id;index:idx_post_id"` - Approved bool `json:"approved" gorm:"index:idx_post_approved"` + PostID string `gorm:"index:idx_post_approved,post_id;index:idx_post_id;type:varchar(19)"` + Approved bool `json:"approved" gorm:"index:idx_post_approved"` Rejected bool `json:"rejected" gorm:"index:idx_post_rejected"` }