go-gorm/gorm · error

the composite tag of %s.%s cannot be empty

Error message

the composite tag of %s.%s cannot be empty

What it means

Error "the composite tag of %s.%s cannot be empty" thrown in go-gorm/gorm.

Source

Thrown at schema/index.go:124

					name       string
					tag        = strings.Join(v[1:], ":")
					idx        = strings.IndexByte(tag, ',')
					tagSetting = strings.Join(strings.Split(tag, ",")[1:], ",")
					settings   = ParseTagSetting(tagSetting, ",")
					length, _  = strconv.Atoi(settings["LENGTH"])
				)

				if idx == -1 {
					idx = len(tag)
				}

				name = tag[0:idx]
				if name == "" {
					subName := field.Name
					const key = "COMPOSITE"
					if composite, found := settings[key]; found {
						if len(composite) == 0 || composite == key {
							err = fmt.Errorf(
								"the composite tag of %s.%s cannot be empty",
								field.Schema.Name,
								field.Name)
							return
						}
						subName = composite
					}
					name = field.Schema.namer.IndexName(
						field.Schema.Table, subName)
				}

				if (k == "UNIQUEINDEX") || settings["UNIQUE"] != "" {
					settings["CLASS"] = "UNIQUE"
				}

				priority, err := strconv.Atoi(settings["PRIORITY"])
				if err != nil {
					priority = 10

View on GitHub (pinned to 1d6ce99528)

Solutions

  1. Add a non-empty composite value in the index tag, e.g. `gorm:"index:,composite:idx_name"`.
  2. Remove the empty composite option from the tag.
  3. Ensure all fields sharing the composite index use the same composite name.

Example fix

Provide a non-empty composite value in the index tag: `gorm:"index:idx_name,composite:col1"`.

When it happens

Trigger: Thrown at schema/index.go:124 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of go-gorm/gorm@1d6ce99528 (2026-08-15). Data as JSON: /api/errors/5579aa8cff84651e. Report an issue: GitHub.