pocketbase/pocketbase · error

no collections to import

Error message

no collections to import

What it means

BaseApp.ImportCollections (core/collection_import.go:39) refuses to import an empty slice. This is an intentional safety guard: with deleteMissing=true the import would otherwise delete ALL non-system collections and their records, so an empty input is treated as an operator error rather than 'import nothing'.

Source

Thrown at core/collection_import.go:39

	err := json.Unmarshal(rawSliceOfMaps, &data)
	if err != nil {
		return err
	}

	return app.ImportCollections(data, deleteMissing)
}

// ImportCollections imports the provided collections data in a single transaction.
//
// For existing matching collections, the imported data is unmarshaled on top of the existing model.
//
// NB! If deleteMissing is true, ALL NON-SYSTEM COLLECTIONS AND SCHEMA FIELDS,
// that are not present in the imported configuration, WILL BE DELETED
// (this includes their related records data).
func (app *BaseApp) ImportCollections(toImport []map[string]any, deleteMissing bool) error {
	if len(toImport) == 0 {
		// prevent accidentally deleting all collections
		return errors.New("no collections to import")
	}

	importedCollections := make([]*Collection, len(toImport))
	mappedImported := make(map[string]*Collection, len(toImport))

	// normalize imported collections data to ensure that all
	// collection fields are present and properly initialized
	for i, data := range toImport {
		var imported *Collection

		identifier := cast.ToString(data["id"])
		if identifier == "" {
			identifier = cast.ToString(data["name"])
		}

		existing, err := app.FindCollectionByNameOrId(identifier)
		if err != nil && !errors.Is(err, sql.ErrNoRows) {
			return err

View on GitHub (pinned to 5d217ddb50)

Solutions

  1. Pass a non-empty collections array in the import payload.
  2. If the intent really was 'no collections', skip the import call entirely.
  3. Check how the import file was loaded — an empty/failed read producing [] instead of an error will surface here.

Example fix

// before
data, _ := os.ReadFile("schema.json") // file missing -> empty
var cols []map[string]any
json.Unmarshal(data, &cols)
app.ImportCollections(cols, true) // -> no collections to import

// after
data, err := os.ReadFile("schema.json")
if err != nil { return err }
if err := json.Unmarshal(data, &cols); err != nil { return err }
if len(cols) == 0 { return errors.New("schema.json contains no collections") }
app.ImportCollections(cols, true)
Defensive patterns

Strategy: validation

Validate before calling

func importCollectionsSafe(app core.App, data []byte, deleteMissing bool) error {
	if len(bytes.TrimSpace(data)) == 0 {
		return errors.New("import file is empty")
	}
	var cols []map[string]any
	if err := json.Unmarshal(data, &cols); err != nil {
		return fmt.Errorf("invalid import json: %w", err)
	}
	if len(cols) == 0 {
		return errors.New("import payload contains no collections — refusing to run")
	}
	return app.ImportCollections(cols, deleteMissing)
}

Try / catch

if err := app.ImportCollections(cols, true); err != nil {
  if strings.Contains(err.Error(), "no collections to import") {
  	log.Warn("skipped import: payload was empty")
  	return nil // treat as a no-op, never as 'delete everything'
  }
  return err
}

Prevention

When it happens

Trigger: Calling ImportCollections([]map[string]any{}, ...) — via the Admin UI's import-collections dialog with an empty file, app.ImportCollections in Go code, or the /api/collections/import endpoint with an empty array body.

Common situations: A YAML/JSON migration file that parsed to zero collections (wrong path, empty fixture); CI importing a generated schema where the generator produced no output; reading a file whose frontmatter consumed everything.

Related errors


AI-assisted analysis of pocketbase/pocketbase@5d217ddb50 (2026-08-15). Data as JSON: /api/errors/17d52269e5740f7a. Report an issue: GitHub.