I have already an Ent model in my go project. But I need to remove some columns from the model. It not works when I update my model. Running migration results runtime error. How can I remove a column from existing model in Ent. ORM?
You can change model simply to remove some fields and this will works if you set WithDropIndex and WithDropColumn options within migration as follow:
WithDropIndex
WithDropColumn
package main import ( "context" "log" "<project>/ent" "<project>/ent/migrate" ) func main() { client, err := ent.Open("mysql", "root:pass@tcp(localhost:3306)/test") if err != nil { log.Fatalf("failed connecting to mysql: %v", err) } defer client.Close() ctx := context.Background() // Run migration. err = client.Schema.Create( ctx, migrate.WithDropIndex(true), migrate.WithDropColumn(true), ) if err != nil { log.Fatalf("failed creating schema resources: %v", err) } }
For more information see documentation
You can change model simply to remove some fields and this will works if you set
WithDropIndex
andWithDropColumn
options within migration as follow:For more information see documentation