payloadcms/payload · error · Error

Invalid database type given. Valid types are: ${Object.value

Error message

Invalid database type given. Valid types are: ${Object.values(dbChoiceRecord).map((dbChoice) => dbChoice.value).join(', ')}

What it means

selectDb throws when --db is passed but its value is not one of the dbChoiceRecord values (d1-sqlite, mongodb, postgres, sqlite, vercel-postgres). The message enumerates the accepted values, and the check uses exact equality against dbChoice.value.

Source

Thrown at packages/create-payload-app/src/lib/select-db.ts:49

    title: 'SQLite',
    value: 'sqlite',
  },
  'vercel-postgres': {
    dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/',
    title: 'Vercel Postgres',
    value: 'vercel-postgres',
  },
}

export async function selectDb(
  args: CliArgs,
  projectName: string,
  template?: ProjectTemplate,
): Promise<DbDetails> {
  let dbType: DbType | symbol | undefined = undefined
  if (args['--db']) {
    if (!Object.values(dbChoiceRecord).some((dbChoice) => dbChoice.value === args['--db'])) {
      throw new Error(
        `Invalid database type given. Valid types are: ${Object.values(dbChoiceRecord)
          .map((dbChoice) => dbChoice.value)
          .join(', ')}`,
      )
    }
    dbType = args['--db'] as DbType
  } else if (template?.dbType) {
    // If the template has a pre-defined database type, use that
    dbType = template.dbType
  } else {
    dbType = await p.select<{ label: string; value: DbType }[], DbType>({
      initialValue: 'mongodb',
      message: `Select a database`,
      options: Object.values(dbChoiceRecord).map((dbChoice) => ({
        label: dbChoice.title,
        value: dbChoice.value,
      })),
    })

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Use one of the exact values printed in the error message (d1-sqlite, mongodb, postgres, sqlite, vercel-postgres).
  2. If you omitted --db, let the interactive prompt choose, or rely on the template's predefined dbType.
  3. Update create-payload-app if you expect a database type added in a newer release.
  4. Strip any surrounding whitespace/quotes from the --db argument.

Example fix

// before
$ npx create-payload-app my-app --db postgre

// after
$ npx create-payload-app my-app --db postgres
Defensive patterns

Strategy: validation

Validate before calling

import { dbChoiceRecord } from './select-db.js'

function assertValidDb(value: string) {
  const valid = Object.values(dbChoiceRecord).map((c) => c.value)
  if (!valid.includes(value as never)) {
    throw new Error(`--db must be one of: ${valid.join(', ')}`)
  }
}

Type guard

const dbTypes = ['d1-sqlite', 'mongodb', 'postgres', 'sqlite', 'vercel-postgres'] as const
type DbType = (typeof dbTypes)[number]
function isDbType(x: string): x is DbType {
  return (dbTypes as readonly string[]).includes(x)
}

Prevention

When it happens

Trigger: Running create-payload-app with --db <type> where <type> is misspelled, deprecated, or not supported by this CLI version (e.g. --db mysql, --db mongo).

Common situations: Using a database identifier from a different docs version; typo like 'postgre' or 'mongo'; passing a value with extra whitespace.

Related errors


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