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
- Confirm `versions: true` (and `drafts` config if used) is set on the collection.
- Restart the process so versions models are rebuilt.
- Await `payload.init()` before calling versions APIs.
- 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
- Set versions: true (or drafts) on collections you call versions APIs on.
- Restart after enabling versions so models rebuild.
- Use the non-versions API when versions aren't enabled.
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
- Collection with the slug ${globalSlug} was not found
- Collection config for ${join.field.collection.toString()} wa
- ERROR: Failed to retrieve collection with the slug "${collec
- ERROR: Failed to retrieve global version model with the slug
- Global with the slug ${globalSlug} was not found
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/6afc50285b6e5022.
Report an issue: GitHub.