#2788·ent

field.ID() still don't work with v0.11.1

Author: BeatsKitanoCreated Jul 23, 2022Updated Feb 26, 2026

this is my define schema

go
package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema"
	"entgo.io/ent/schema/field"
)

// SampleFavorite holds the schema definition for the SampleFavorite entity.
type SampleFavorite struct {
	ent.Schema
}

// Fields of the FavoriteSample.
func (SampleFavorite) Fields() []ent.Field {
	return []ent.Field{
		field.Time("create_time").Immutable(),

		field.Int("favoritor_id"),
		field.Int("sample_id"),
	}
}

func (SampleFavorite) Annotations() []schema.Annotation {
	return []schema.Annotation{
		field.ID("favoritor_id", "sample_id"),
	}
}

Current Behavior

I got ent error output when i excute follow command

bash
go generate ./...

execute template "model": template: ent.tmpl:37:30: executing "model" at <$.Annotations.Fields.StructTag.id>: nil pointer evaluating interface {}.id
exit status 1
internal/data/ent/generate.go:3: running "go": exit status 1
make: *** [generate] Error 1

Expected Behavior

Expect to generate multi-key primary

Your Environment

Tech Version
Go 1.18.4
Ent 0.11.1
Database PostgreSQL
Driver https://github.com/jackc/pgx/v4/stdlib