{"record":{"id":"46ebb898f57fa7f4","repo":"hasura/graphql-engine","slug":"error-while-applying-seeds-for-database-s-w","errorCode":null,"errorMessage":"error while applying seeds for database '%s': %w","messagePattern":"error while applying seeds for database '(.+?)': %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/seed_apply.go","lineNumber":121,"sourceCode":"\n\tif o.EC.AllDatabases && o.EC.Config.Version >= cli.V3 {\n\t\tsourcesAndKind, err := metadatautil.GetSourcesAndKind(\n\t\t\to.EC.APIClient.V1Metadata.ExportMetadata,\n\t\t)\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"got error while getting the sources list : %w\", err))\n\t\t}\n\n\t\tfor _, source := range sourcesAndKind {\n\t\t\to.Source = cli.Source(source)\n\n\t\t\terr := o.ApplyOnSource()\n\t\t\tif err != nil {\n\t\t\t\t// skip error if no seed files are specified and no seeds are present\n\t\t\t\tif len(o.FileNames) > 0 || !stderrors.Is(err, fs.ErrNotExist) {\n\t\t\t\t\treturn errors.E(\n\t\t\t\t\t\top,\n\t\t\t\t\t\tfmt.Errorf(\n\t\t\t\t\t\t\t\"error while applying seeds for database '%s': %w\",\n\t\t\t\t\t\t\to.Source.Name,\n\t\t\t\t\t\t\terr,\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\to.EC.Logger.Infof(\"No seed data to plant for database: %s\", o.Source.Name)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\to.EC.Logger.Infof(\"Seed data planted for database: %s\", o.Source.Name)\n\t\t\t}\n\t\t}\n\t} else {\n\t\to.Source = o.EC.Source\n\n\t\terr := o.ApplyOnSource()\n\t\tif err != nil {\n\t\t\treturn errors.E(op, err)","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/seed_apply.go#L103-L139","documentation":"Thrown when applying seed SQL files to a Hasura metadata source database fails. The underlying error comes from ApplyOnSource, which executes the seed files against the source database. It is suppressed only when no seed files were specified and the error is fs.ErrNotExist (i.e., no seeds directory exists).","triggerScenarios":"Running `hasura seed apply` (or code calling SeedApply.Run) where the seeds directory or specified --file paths cannot be read, the SQL fails to execute against the source database, or the source connection is unreachable. Suppression only applies when len(o.FileNames) == 0 and the error is fs.ErrNotExist.","commonSituations":"Typos in --file paths, seeds/ directory missing while explicit file names were passed, malformed seed SQL (syntax errors, constraint violations), wrong DATABASE_URL or unreachable Postgres, MSSQL/Citus sources where seed ops differ.","solutions":["Verify the seeds directory exists (default seeds/) or that every --file/--enum-files path passed is correct and readable","Check the wrapped error: if it's a SQL error, run the seed file manually against the source database (psql) to find the failing statement","Confirm the source database connection (Hasura metadata DB env / --database-url) is reachable and credentials are valid","If seeds are intentionally absent, run without --file so the fs.ErrNotExist suppression path applies"],"exampleFix":"// before\nhasura seed apply --file ./seeds/missing_file.sql\n// after\nmkdir -p seeds && echo 'INSERT INTO users ...;' > seeds/users.sql\nhasura seed apply --file ./seeds/users.sql","handlingStrategy":"validation","validationCode":"// before invoking seed apply\nif len(seedFileNames) > 0 {\n    for _, f := range seedFileNames {\n        if _, err := os.Stat(f); err != nil {\n            return fmt.Errorf(\"seed file %s not accessible: %w\", f, err)\n        }\n    }\n} else if _, err := os.Stat(\"seeds\"); os.IsNotExist(err) {\n    // no seeds dir and no files: skip apply entirely\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// Inspect the wrapped error to distinguish fs.ErrNotExist from SQL failures\nif err := seedApply.Run(); err != nil {\n    var pathErr *fs.PathError\n    if errors.As(err, &pathErr) && errors.Is(pathErr.Err, fs.ErrNotExist) {\n        // missing seeds directory — safe to ignore or log info\n        return nil\n    }\n    return err\n}","preventionTips":["Keep seed files under the default seeds/ directory with .sql extensions","Validate --file paths exist before scripting seed apply in CI","Smoke-test seed SQL against the source DB before committing"],"tags":["hasura","seed","sql","database","cli"],"backgroundTag":"sql-seed-apply-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}