Prisma Schema Now() + 1 year

Viewed 1495

When defining a schema in prisma, providing now() as default datetime field value is possible.

Is it possible to provide now()+ 1 year as default ?

All my attemps have failed.

1 Answers

You can use the dbgenerated() function to call native database functions and assign the return value as the default value of a certain field in your Prisma model.

If you're using PostgreSQL, your Prisma schema would look like this:

model foo {
  id Int @id
  createdAt DateTime @default(dbgenerated("NOW() + interval '1 year'"))   // Default value is 1 year from now. 

  // ... other fields
}
Related