Manually setting `_createdAt` field after creation time in Sanity.io.
Unfortunately, _createdAt cannot be modified after a document is first created, even through migrations. According to Sanity's documentation on setting created and modified dates:
You can set the
_createdAtattribute the first time you create a document, but it cannot be modified in subsequent mutations (without deleting and recreating the document).
Your options for fixing this:
1. Create custom editorial date fields (Recommended)
The best approach is to create your own datetime fields in your schema for editorial purposes. These fields are fully editable and can be set during migration or updated anytime:
defineField({
name: 'originalCreatedAt',
type: 'datetime',
title: 'Original Creation Date',
description: 'The original creation date from the imported content',
})You can then populate these fields with a migration script using the migration tooling or the Sanity Client.
2. Delete and recreate documents (Nuclear option)
If you absolutely need the system _createdAt field to reflect the original dates, you'd have to:
- Delete the existing documents
- Recreate them with
_createdAtset to the original dates in yourcreatemutation
Important: When you first create a document, you CAN set _createdAt to any value you want. It's only locked after that initial creation.
3. Run a new migration with correct dates
If you still have access to your original data source, you could:
- Create a new dataset (or use the same one after backing up)
- Re-run your migration, this time including the original dates in your
createmutations:
const doc = {
_id: 'imported-post-123',
_type: 'post',
_createdAt: originalPost.created, // Set it during initial creation
title: originalPost.title,
// ... other fields
}
await client.create(doc)The editorial date field approach (option 1) is generally the best practice, as it gives you full control over dates that matter to your content team, while the system _createdAt/_updatedAt fields track actual mutation history in Sanity.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.