{"record":{"id":"fea80b654e90f13b","repo":"go-gorm/gorm","slug":"failed-to-create-index-with-name-s","errorCode":null,"errorMessage":"failed to create index with name %s","messagePattern":"failed to create index with name (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"migrator/migrator.go","lineNumber":865,"sourceCode":"\t\t\t}\n\t\t\tcreateIndexSQL += \"INDEX ? ON ??\"\n\n\t\t\tif idx.Type != \"\" {\n\t\t\t\tcreateIndexSQL += \" USING \" + idx.Type\n\t\t\t}\n\n\t\t\tif idx.Comment != \"\" {\n\t\t\t\tcreateIndexSQL += fmt.Sprintf(\" COMMENT '%s'\", idx.Comment)\n\t\t\t}\n\n\t\t\tif idx.Option != \"\" {\n\t\t\t\tcreateIndexSQL += \" \" + idx.Option\n\t\t\t}\n\n\t\t\treturn m.DB.Exec(createIndexSQL, values...).Error\n\t\t}\n\n\t\treturn fmt.Errorf(\"failed to create index with name %s\", name)\n\t})\n}\n\n// DropIndex drop index `name`\nfunc (m Migrator) DropIndex(value interface{}, name string) error {\n\treturn m.RunWithValue(value, func(stmt *gorm.Statement) error {\n\t\tif stmt.Schema != nil {\n\t\t\tif idx := stmt.Schema.LookIndex(name); idx != nil {\n\t\t\t\tname = idx.Name\n\t\t\t}\n\t\t}\n\n\t\treturn m.DB.Exec(\"DROP INDEX ? ON ?\", clause.Column{Name: name}, m.CurrentTable(stmt)).Error\n\t})\n}\n\n// HasIndex check has index `name` or not\nfunc (m Migrator) HasIndex(value interface{}, name string) bool {","sourceCodeStart":847,"sourceCodeEnd":883,"githubUrl":"https://github.com/go-gorm/gorm/blob/1d6ce99528060be18a42be09aca8d39efcb47f28/migrator/migrator.go#L847-L883","documentation":"Error \"failed to create index with name %s\" thrown in go-gorm/gorm.","triggerScenarios":"Thrown at migrator/migrator.go:865 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the index name is valid for the database (length and character limits).","Drop the conflicting existing index with that name before creating it.","Ensure the columns referenced by the index exist on the table."],"exampleFix":"Check the index name is unique and valid before CreateIndex: if !db.Migrator().HasIndex(&m, name) { db.Migrator().CreateIndex(&m, name) }","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1d6ce99528060be18a42be09aca8d39efcb47f28","analyzedAt":"2026-08-15T13:01:23.433Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}