Hey all, I hope everyone is ok. Do you know how to...
# orm-help
f
Hey all, I hope everyone is ok. Do you know how to create a DateTime field with default value "now"? I have the field
publishedAt
and it should have the same value that the field
createdAt
. I tried
publishedAt: DateTime! @default(now())
,
publishedAt: DateTime! @default(value: "now()")
,
publishedAt: DateTime! @default(value: Date.now())
,
publishedAt: DateTime! @default(@createdAt)
and none of this options worked as expected. Is there a possibility to create a DateTime field with a default value without being the createdAt and UpdatedAt fields?
👀 1
m
I'm not sure which version of Prisma you're using. When I put a bang on a type
DateTime!
, I get a message
Fields are required by default.  '!' is not longer required.
I've never had any problem with
publishedAt DateTime @default(now())
- could it be your
!
that's causing the issue?
Also (and again - maybe this is a version thing) why are you putting a
:
after your field declaration. In version 3, "field declarations don't require a
:
"
f
Sorry, I forgot to mention the prisma version. It's
1.34.8
. I think another important thing to say it's the DateTime is a
scalar type
. Could this affect the default value? So, basically, I have this:
Copy code
type Workout {
  ...
  @scalarList(strategy: RELATION)
  publishedAt: DateTime @default(now())
  ...
}

scalar DateTime
This is the error when I try to deploy
Copy code
ERROR: Syntax error while parsing GraphQL query. Invalid input "RELATION)\n  publishedAt: DateTime @default(now(", expected Value, Argument, Directive or FieldDefinition (line 121, column 49):
  spotifyUris: [String!]! @scalarList(strategy: RELATION)
                                                ^

{
  "data": {
    "deploy": null
  },
  "errors": [
    {
      "locations": [
        {
          "line": 2,
          "column": 9
        }
      ],
      "path": [
        "deploy"
      ],
      "code": 3017,
      "message": "Syntax error while parsing GraphQL query. Invalid input \"RELATION)\\n  publishedAt: DateTime @default(now(\", expected Value, Argument, Directive or FieldDefinition (line 121, column 49):\n  spotifyUris: [String!]! @scalarList(strategy: RELATION)\n                                                ^",
      "requestId": "local:cl69keufr000s0868zjm14ldx"
    }
  ],
  "status": 200
}
m
I wish I could help. I'm using Prisma v3 and do what you're trying to do with no problem.
☹️ 1
n
Hey Felipe 👋 As this is related to Prisma 1, @andrewicarlson might be able to help you. I had a look at the documentation but couldn’t find the exact way through which you could achieve this.