{"record":{"id":"c4911ffc27dd9ca0","repo":"ent/ent","slug":"ent-migrate-w","errorCode":null,"errorMessage":"ent/migrate: %w","messagePattern":"ent/migrate: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"entc/gen/template/dialect/sql/feature/migratediff.tmpl","lineNumber":26,"sourceCode":"\n{{ define \"migrate/diff\" }}\n// Diff compares the state read from a database connection or migration directory with\n// the state defined by the Ent schema. Changes will be written to new migration files.\nfunc Diff(ctx context.Context, url string, opts ...schema.MigrateOption) error {\n    return NamedDiff(ctx, url, \"changes\", opts...)\n}\n\n// NamedDiff compares the state read from a database connection or migration directory with\n// the state defined by the Ent schema. Changes will be written to new named migration files.\nfunc NamedDiff(ctx context.Context, url, name string, opts ...schema.MigrateOption) error {\n    return schema.Diff(ctx, url, name, Tables, opts...)\n}\n// Diff creates a migration file containing the statements to resolve the diff\n// between the Ent schema and the connected database.\nfunc (s *Schema) Diff(ctx context.Context, opts ...schema.MigrateOption) error {\n    migrate, err := schema.NewMigrate(s.drv, opts...)\n    if err != nil {\n        return fmt.Errorf(\"ent/migrate: %w\", err)\n    }\n    return migrate.Diff(ctx, Tables...)\n}\n\n// NamedDiff creates a named migration file containing the statements to resolve the diff\n// between the Ent schema and the connected database.\nfunc (s *Schema) NamedDiff(ctx context.Context, name string, opts ...schema.MigrateOption) error {\n    migrate, err := schema.NewMigrate(s.drv, opts...)\n    if err != nil {\n        return fmt.Errorf(\"ent/migrate: %w\", err)\n    }\n    return migrate.NamedDiff(ctx, name, Tables...)\n}\n{{ end }}","sourceCodeStart":8,"sourceCodeEnd":40,"githubUrl":"https://github.com/ent/ent/blob/69d5d4deb19599f129166634e09d33addcf3f2cc/entc/gen/template/dialect/sql/feature/migratediff.tmpl#L8-L40","documentation":"This error is returned by the generated Schema.Diff method when creating a new schema.Migrate fails (e.g. the configured driver does not support the diff/migration feature). The library wraps the underlying error with the 'ent/migrate: ' prefix so callers can identify migration-layer failures. It is produced by the migratediff.tmpl code-generation template for all SQL dialects.","triggerScenarios":"Calling Schema.Diff(ctx, opts...) (or VersionedMigration variants) where schema.NewMigrate fails, typically because the dialect driver lacks the migrate/diff capability.","commonSituations":"Using a custom or third-party driver that does not implement the migration interface; enabling Atlas-based versioned migrations with an incompatible driver; dialect misconfiguration in the generated ent client.","solutions":["Inspect the wrapped error (errors.Unwrap / %v of the returned error) to find why schema.NewMigrate failed","Verify the dialect driver passed to the schema supports the migration/diff interface","Ensure the generated code and the ent dialect package versions match (regenerate with the same ent version)","Switch to the official dialect driver (e.g. sql dialect via atlas) if a custom driver is in use"],"exampleFix":"// before\ncs, err := entsql.Open(dialect.MySQL, dsn)\nerr = client.Schema.Diff(ctx)\n// after\n// use a driver that supports diff, e.g. the official sql driver, and check the wrapped cause\nif err != nil {\n    log.Fatalf(\"migration diff failed: %v\", err) // shows underlying NewMigrate cause\n}","handlingStrategy":"try-catch","validationCode":"// Go: check driver capability before Diff\nif _, ok := drv.(interface {\n\tBeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)\n}); !ok {\n\treturn fmt.Errorf(\"driver %T does not support migrations\", drv)\n}","typeGuard":"func supportsMigrate(drv dialect.Driver) bool {\n\t_, ok := drv.(interface {\n\t\tBeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)\n\t})\n\treturn ok\n}","tryCatchPattern":"err := client.Schema.Diff(ctx)\nif err != nil {\n\tvar base error\n\tif errors.As(err, &base) { /* log unwrapped NewMigrate cause */ }\n\treturn fmt.Errorf(\"migration diff failed: %w\", err)\n}","preventionTips":["Always use official dialect drivers for migration diffs","Keep ent and dialect package versions in sync via go.mod","Run migrations in CI against a disposable database to catch driver issues early"],"tags":["go","ent","migration","codegen"],"backgroundTag":"migration-driver-unsupported","analyzedSha":"69d5d4deb19599f129166634e09d33addcf3f2cc","analyzedAt":"2026-09-03T16:51:39.799Z","contentChangedAt":"2026-09-03T16:51:39.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}