{"id":"5489ba6e8c7ec09f","repo":"go-redis/redis","slug":"ft-create-schema-fieldname-and-fieldtype-are-requ","errorCode":null,"errorMessage":"FT.CREATE: SCHEMA FieldName and FieldType are required","messagePattern":"FT\\.CREATE: SCHEMA FieldName and FieldType are required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_commands.go","lineNumber":1455,"sourceCode":"\t\t}\n\t\tif options.StopWords != nil {\n\t\t\targs = append(args, \"STOPWORDS\", len(options.StopWords))\n\t\t\targs = append(args, options.StopWords...)\n\t\t}\n\t\tif options.SkipInitialScan {\n\t\t\targs = append(args, \"SKIPINITIALSCAN\")\n\t\t}\n\t}\n\tif schema == nil {\n\t\tcmd := NewStatusCmd(ctx, args...)\n\t\tcmd.SetErr(fmt.Errorf(\"FT.CREATE: SCHEMA is required\"))\n\t\treturn cmd\n\t}\n\targs = append(args, \"SCHEMA\")\n\tfor _, schema := range schema {\n\t\tif schema.FieldName == \"\" || schema.FieldType == SearchFieldTypeInvalid {\n\t\t\tcmd := NewStatusCmd(ctx, args...)\n\t\t\tcmd.SetErr(fmt.Errorf(\"FT.CREATE: SCHEMA FieldName and FieldType are required\"))\n\t\t\treturn cmd\n\t\t}\n\t\targs = append(args, schema.FieldName)\n\t\tif schema.As != \"\" {\n\t\t\targs = append(args, \"AS\", schema.As)\n\t\t}\n\t\targs = append(args, schema.FieldType.String())\n\t\tif schema.VectorArgs != nil {\n\t\t\tif schema.FieldType != SearchFieldTypeVector {\n\t\t\t\tcmd := NewStatusCmd(ctx, args...)\n\t\t\t\tcmd.SetErr(fmt.Errorf(\"FT.CREATE: SCHEMA FieldType VECTOR is required for VectorArgs\"))\n\t\t\t\treturn cmd\n\t\t\t}\n\t\t\t// Check mutual exclusivity of vector options\n\t\t\toptionCount := 0\n\t\t\tif schema.VectorArgs.FlatOptions != nil {\n\t\t\t\toptionCount++\n\t\t\t}","sourceCodeStart":1437,"sourceCodeEnd":1473,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/search_commands.go#L1437-L1473","documentation":"Returned by FTCreate when a FieldSchema entry has an empty FieldName or FieldType==SearchFieldTypeInvalid. Both are mandatory because RediSearch needs a name and a concrete type token (TEXT/NUMERIC/TAG/...). SearchFieldTypeInvalid is the zero value (String() returns \"\"), so an uninitialized FieldSchema trips this guard at search_commands.go:1453.","triggerScenarios":"Passing a &FieldSchema{} literal with FieldName unset, setting FieldType via a variable that defaulted to zero, or constructing schemas in a loop where one iteration leaves the fields blank.","commonSituations":"Forgetting to set FieldType when the zero value is acceptable-looking (it compiles to the Invalid iota), populating FieldName from a config key that is missing, or partial struct copy that dropped FieldType.","solutions":["Set both FieldName (non-empty string) and FieldType (e.g. SearchFieldTypeText, SearchFieldTypeTag) on every FieldSchema.","Validate each FieldSchema in a helper before calling FTCreate to fail early with a clearer message.","Linter/assertion: ensure no FieldSchema in the slice has FieldType == SearchFieldTypeInvalid."],"exampleFix":"// before\n&redis.FieldSchema{FieldName: \"\", FieldType: redis.SearchFieldTypeInvalid}\n\n// after\n&redis.FieldSchema{FieldName: \"title\", FieldType: redis.SearchFieldTypeText}","handlingStrategy":"validation","validationCode":"for i, f := range fields {\n    if f.FieldName == \"\" || f.FieldType == redis.SearchFieldTypeInvalid {\n        return fmt.Errorf(\"fields[%d]: FieldName and FieldType are required\", i)\n    }\n}","typeGuard":"func isValidFieldSchema(f *redis.FieldSchema) bool {\n    return f != nil && f.FieldName != \"\" && f.FieldType != redis.SearchFieldTypeInvalid\n}","tryCatchPattern":"if err := cmd.Err(); err != nil {\n    if strings.Contains(err.Error(), \"FieldName and FieldType are required\") {\n        // inspect each FieldSchema for blanks\n    }\n}","preventionTips":["Treat the zero-value FieldSchema as a bug; never pass &redis.FieldSchema{}.","Validate the schema slice in a loop before FTCreate.","Add a test asserting every FieldSchema has a non-empty name and non-Invalid type."],"tags":["redisearch","ft-create","schema","validation","zero-value"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}