Error: Cannot cast type bigint to uuid (SQLSTATE 42846)

98 views Asked by At

I don't understand why I am getting the below error, my application is a REST API that does basic CRUD operations. I am using gin and gorm. Why is the below issue happening? I am getting the below error

ERROR: Cannot cast type bigint to uuid (SQLSTATE 42846)
[row:0] ALTER TABLE "containers" ALTER COLUMN "env_id" TYPE uuid USING "env_id"::uuid

My Schema looks as below and I am calling Automigrate. Every env contains multiple containers and every containers contain multiple Apps. I am trying to build a map that shows Env and all containers in it and all apps in containers. I am not sure what is wrong here, I am not using bigint anywhere. Thank You

package models

import (
"github.com/google/uuid"
"gorm.io/gorm"
)
type Env struct {
gorm.Model
Name string \json:"name"`Env_Id. uuid.UUID `gorm:"type:uuid;primaryKey" json:"env_id"`Containers []Container `gorm:"foreignKey:Env_Id;references:Env_Id" json:"containers"`}`

package models
import (
"github.com/google/uuid"
"gorm.io/gorm"
)
type Container struct {
gorm.Model
ID uuid.UUID \gorm:"type:uuid;primary_key;" json:"id"`Num int `json:"num"`Env_Id uuid.UUID `gorm:"type:uuid;column:env_id" json:"env_id"`Apps []App `gorm:"foreignKey:Container_Id;references:ID" json:"apps"`}`

package models
import (
"github.com/google/uuid"
"gorm.io/gorm"
)
type App struct {
gorm.Model
App_label string \json:"app_label"`App_No int `json:"app_no"`App_Id uuid.UUID `gorm:"type:uuid;primaryKey" json:"app_id"`Container_Id uuid.UUID `gorm:"type:uuid" json:"container_id"`}`
0

There are 0 answers