Like what we’re doing? Star us on GitHub!

Changing Field uniqueness after content has been created, changes do not take effect?

3 months ago
1 1

I made a field "unique". Now content has already been created and I realized I can't duplicate the document because of this field. I then removed the unique prop, but the validation still kicks in, it doesn't matter if I create a new document or edit an old one.

Does this have to do with the version history of already created files? Is this a bug? Can I fix this without clearing parts of the database?

Thanks for any help.

  • JarrodMFlesch
    Payload Team
    3 months ago

    @christian-reichart You should be able to connect to your db and then remove the index that gets created for unique fields. Are you using something like MongoDB Compass? You just need to go to the collection, then click the indexes tab and remove the index related to your unique field đź‘Ť

    3 replies
  • christian-reichart
    3 months ago

    Thanks @JarrodMFlesch for the answer! The problem currently exists on a staging environment were I haven't set up direct access to the db yet. Will try this once I have set this up.

    Just to clarify and understand the problem: Is this something that was looked over and can be fixed in a future version of Payload? Or does this fall und the general topic of db migration and is not seen as part of Payload (although automated migrations would be awesome! :D)

  • DanRibbens
    Payload Team
    3 months ago

    @christian-reichart, you inspired me to do a proof of concept of a Payload project with migrations! See

    It certainly isn't automatic based on changes, but I don't think that would be possible anyways.

    I'll write a blog post on and depending on reception, would love to get your feedback on it when it is live. I would consider adding this workflow to the Payload docs, but I don't know that this goes into the core just yet.

  • christian-reichart
    3 months ago

    Wow this is really helpful and looks awesome! Thanks so much! Excited for the blog post.

Open the post
Continue the discussion in GitHub
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More