ValidationError: The following field is invalid: email, but no email field in collection

default discord avatar
gak4ulast year

Hi Everyone,

I have following user collection which where I am not using authentication in payload cms, rather I have a SvelteKit app where i'm handling auth.

import { CollectionConfig, Field } from 'payload/types'; import {isAdmin, isAdminOrSelf} from '../access/Access'; const Users: CollectionConfig = { slug: 'users', admin: { useAsTitle: 'mobile', }, access: { read: isAdminOrSelf('id'), create: isAdminOrSelf('id'), update: isAdminOrSelf('id'), delete: isAdmin, }, fields: [ { name: 'mobile', type: 'text', required: true, unique: true, label: 'Mobile', }, { name: 'first_name', type: 'text', label: 'First Name', }, { name: 'last_name', type: 'text', label: 'Last Name', }, { name: 'membership', type: 'select', options: [ { label: 'Premium', value: 'premium' }, { label: 'Basic', value: 'basic' }, ], defaultValue: 'basic', }, ] }; export default Users;

But I am getting following error while creating a new record from payload cms admin

ERROR (payload): ValidationError: The following field is invalid: email at create (/Users/anil/Projects/RN/vqard-be/node_modules/payload/src/collections/operations/create.ts:215:11) at processTicksAndRejections (node:internal/process/task_queues:96:5) at createHandler (/Users/anil/Projects/RN/vqard-be/node_modules/payload/src/collections/requestHandlers/create.ts:19:17)

Any pointers will be very helpful. TIA

For authentication, I am using a different collection called AdminUser

After digging a little I found that error is little misleading. This error is being thrown for duplicate email key from mongoose. Somehow mongoose is still validating for duplicate email which is basically null. So I didn’t had any problem for first user

  • default discord avatar
    .hawk_e12 months ago

    Check for a email index in your Users collection and delete it. Payload creates a index when the project is bootstraped

  • discord user avatar
    12 months ago

    @.hawk_e — nailed it, this is the issue for sure

    we don't ever delete indexes for you

    so there's still a


    index in place

Star on GitHub


Chat on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.