I am trying to figure out how to post a date to a prisma database.
I have a prisma.schema which has a createdAt field as follows:
createdAt DateTime @default(now()) @db.Timestamptz(6)
I made a model with a date field in it as follows:
@Field()
createdAt: Date;
And a create.input.ts with a similar field:
@IsNotEmpty()
@Field()
createdAt: Date;
then, in the form, I'm trying to add the createdAt date as the date the form is submitted, as follows:
return form.handler(() => createIssueGroup({ variables: { data: { ...data, createdAt: Date.now() } } })),
However, I get an error that says type number is not assignable to type string. I don't think I'm using a string in any of the date fields.
How can I post a date to prisma?
From your schema definition,
createdAt DateTime @default(now()) @db.Timestamptz(6)
The date will be automatically generated due to the now()
method you specified in @default()
. You don't need to pass a date to the database as that will be handled for you by Prisma. See the docs for more information on using now() and defining a default value.