payloadcms/payload · error · APIError

ERROR: Failed to retrieve collection version model with the

Error message

ERROR: Failed to retrieve collection version model with the slug "${collectionSlug}". Does not exist.

What it means

Thrown by `getEntity` when `versions: true` is requested but `adapter.versions[collectionSlug]` is undefined — the versions Mongoose model was never built. This means versions/drafts are not enabled on that collection, or the model build was skipped/raced.

Source

Thrown at packages/db-mongodb/src/utilities/getEntity.ts:34

}): {
  collectionConfig: SanitizedCollectionConfig
  customIDType: Collection['customIDType']

  Model: CollectionModel
} => {
  const collection = adapter.payload.collections[collectionSlug]

  if (!collection) {
    throw new APIError(
      `ERROR: Failed to retrieve collection with the slug "${collectionSlug}". Does not exist.`,
    )
  }

  if (versions) {
    const Model = adapter.versions[collectionSlug]

    if (!Model) {
      throw new APIError(
        `ERROR: Failed to retrieve collection version model with the slug "${collectionSlug}". Does not exist.`,
      )
    }

    return { collectionConfig: collection.config, customIDType: collection.customIDType, Model }
  }

  const Model = adapter.collections[collectionSlug]

  if (!Model) {
    throw new APIError(
      `ERROR: Failed to retrieve collection model with the slug "${collectionSlug}". Does not exist.`,
    )
  }

  return { collectionConfig: collection.config, customIDType: collection.customIDType, Model }
}

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Confirm `versions: true` (and `drafts` config if used) is set on the collection.
  2. Restart the process so versions models are rebuilt.
  3. Await `payload.init()` before calling versions APIs.
  4. If versions are genuinely not enabled, use the non-versions API instead.

Example fix

// before
{ slug: 'posts', versions: false }
await payload.findVersions({ collection: 'posts' })
// after
{ slug: 'posts', versions: { drafts: true } }
await payload.findVersions({ collection: 'posts' })
Defensive patterns

Strategy: validation

Validate before calling

function assertVersionsEnabled(payload, slug) {
  const enabled = payload.collections[slug]?.config?.versions
  if (!enabled) throw new Error(`Versions not enabled on ${slug}`)
}

Type guard

const hasVersionsEnabled = (payload, s) =>
  Boolean(payload.collections[s]?.config?.versions)

Try / catch

try { await payload.findVersions({ collection: slug }) }
catch (e) { if (/version model with the slug/.test(e.message)) enableVersionsOrUseBaseApi(slug) else throw e }

Prevention

When it happens

Trigger: Calling a versions-aware operation (`findVersions`, `findVersionByID`, `deleteVersion`, `restoreVersion`, etc.) on a collection whose config does not have `versions: true`, or before the versions models were built during init.

Common situations: `versions: false` (or omitted) on the collection but the caller requests versions; config changed to enable versions but the process wasn't restarted; init race; drafts config inconsistency.

Related errors


AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12). Data as JSON: /api/errors/6afc50285b6e5022. Report an issue: GitHub.