hasura/graphql-engine · error
error while applying seeds for database '%s': %w
Error message
error while applying seeds for database '%s': %w
What it means
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).
Source
Thrown at cli/commands/seed_apply.go:121
if o.EC.AllDatabases && o.EC.Config.Version >= cli.V3 {
sourcesAndKind, err := metadatautil.GetSourcesAndKind(
o.EC.APIClient.V1Metadata.ExportMetadata,
)
if err != nil {
return errors.E(op, fmt.Errorf("got error while getting the sources list : %w", err))
}
for _, source := range sourcesAndKind {
o.Source = cli.Source(source)
err := o.ApplyOnSource()
if err != nil {
// skip error if no seed files are specified and no seeds are present
if len(o.FileNames) > 0 || !stderrors.Is(err, fs.ErrNotExist) {
return errors.E(
op,
fmt.Errorf(
"error while applying seeds for database '%s': %w",
o.Source.Name,
err,
),
)
} else {
o.EC.Logger.Infof("No seed data to plant for database: %s", o.Source.Name)
}
} else {
o.EC.Logger.Infof("Seed data planted for database: %s", o.Source.Name)
}
}
} else {
o.Source = o.EC.Source
err := o.ApplyOnSource()
if err != nil {
return errors.E(op, err)View on GitHub (pinned to 724551b9ae)
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
Example fix
// before hasura seed apply --file ./seeds/missing_file.sql // after mkdir -p seeds && echo 'INSERT INTO users ...;' > seeds/users.sql hasura seed apply --file ./seeds/users.sql
Defensive patterns
Strategy: validation
Validate before calling
// before invoking seed apply
if len(seedFileNames) > 0 {
for _, f := range seedFileNames {
if _, err := os.Stat(f); err != nil {
return fmt.Errorf("seed file %s not accessible: %w", f, err)
}
}
} else if _, err := os.Stat("seeds"); os.IsNotExist(err) {
// no seeds dir and no files: skip apply entirely
return nil
} Try / catch
// Inspect the wrapped error to distinguish fs.ErrNotExist from SQL failures
if err := seedApply.Run(); err != nil {
var pathErr *fs.PathError
if errors.As(err, &pathErr) && errors.Is(pathErr.Err, fs.ErrNotExist) {
// missing seeds directory — safe to ignore or log info
return nil
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- exporting seed data: %w
- cannot find default editor from env: %w
- failed to create seed file: %w
- error serving console: %w
- operation failed: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/46ebb898f57fa7f4.
Report an issue: GitHub.