gen
gen copied to clipboard
Insert error caused by PostgreSQL default value
create table sql
create SCHEMA test;
CREATE TYPE "public".fruit_color AS ENUM ('unknown', 'red', 'green', 'orange');
create table "test"."fruits"(
"name" varchar(64) COLLATE "pg_catalog"."default" DEFAULT ''::character varying,
"color" "public"."fruit_color" NOT NULL DEFAULT 'unknown'::fruit_color
)
fruits.gen.go
package types
const TableNameFruit = "fruits"
// Fruit mapped from table <fruits>
type Fruit struct {
Name string `gorm:"column:name;type:character varying(64);default:''::character varying" json:"name"`
Color string `gorm:"column:color;type:public.fruit_color;not null;default:'unknown'::public.fruit_color" json:"color"`
}
// TableName Fruit's table name
func (*Fruit) TableName() string {
return TableNameFruit
}
name default value is ::character varying not empty string.
color default value is 'unknown'::public.fruit_color not unknown.