diff --git a/entc/gen/type.go b/entc/gen/type.go index bdd2ba454..521e017fc 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -575,7 +575,7 @@ func (t *Type) checkField(tf *Field, f *load.Field) (err error) { err = fmt.Errorf("invalid type for field %s", f.Name) case f.Nillable && !f.Optional: err = fmt.Errorf("nillable field %q must be optional", f.Name) - case f.Unique && f.Default: + case f.Unique && f.Default && f.Info.Type != field.TypeUUID: err = fmt.Errorf("unique field %q cannot have default value", f.Name) case t.fields[f.Name] != nil: err = fmt.Errorf("field %q redeclared for type %q", f.Name, t.Name) diff --git a/entc/integration/customid/ent/migrate/schema.go b/entc/integration/customid/ent/migrate/schema.go index e2e97801a..2c34afde7 100644 --- a/entc/integration/customid/ent/migrate/schema.go +++ b/entc/integration/customid/ent/migrate/schema.go @@ -15,7 +15,7 @@ var ( // BlobsColumns holds the columns for the "blobs" table. BlobsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, - {Name: "uuid", Type: field.TypeUUID}, + {Name: "uuid", Type: field.TypeUUID, Unique: true}, {Name: "blob_parent", Type: field.TypeUUID, Unique: true, Nullable: true}, } // BlobsTable holds the schema information for the "blobs" table. diff --git a/entc/integration/customid/ent/schema/blob.go b/entc/integration/customid/ent/schema/blob.go index 32637c1a8..28a7e5fb1 100644 --- a/entc/integration/customid/ent/schema/blob.go +++ b/entc/integration/customid/ent/schema/blob.go @@ -23,7 +23,8 @@ func (Blob) Fields() []ent.Field { field.UUID("id", uuid.UUID{}). Default(uuid.New), field.UUID("uuid", uuid.UUID{}). - Default(uuid.New), + Default(uuid.New). + Unique(), } }