`createdAt @default(now())` and `updatedAt @updatedAt` get different times on row creation
See original GitHub issueBug description
I have standard table like this:
model User {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
I always assumed that after a prisma.user.create({})
, the createdAt
and updatedAt
would be the same dates, matching to the millisecond. I’m seeing that’s not the case and updatedAt
many times has a few extra millisecond(s).
How to reproduce
- Create the table above
- Add many rows and log the query result
- You’ll see what I describe eventually
Expected behavior
On creation, createdAt
and updatedAt
are always identical.
I suppose if @updatedAt
kind of columns would also default to CURRENT_TIMESTAMP
like the default(now())
do, the problem would be resolved
Prisma information
The schema above is enough
Environment & setup
- OS: Ubuntu 20
- Database: PostgreSQL
- Node.js version: v14.17.0
Prisma Version
prisma : 3.6.0
@prisma/client : 3.6.0
Current platform : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine : migration-engine-cli dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary : prisma-fmt dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : dc520b92b1ebb2d28dc3161f9f82e875bd35d727
Studio : 0.440.0
Preview Features : filterJson
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Nexus Prisma - How to handle createdAt and updatedAt ...
When using @default(now()) and @updatedAt set 2 differents timestamp when created, determine if a record have been updated using createdAt !==
Read more >Schema Incompatibilities | PostgreSQL
Manually add the @default(now()) attribute to the Prisma model ... If the @updatedAt attribute is set in the Prisma schema and you run...
Read more >11.2.5 Automatic Initialization and Updating for ...
An auto-updated column is automatically updated to the current timestamp when the value of any other column in the row is changed from...
Read more >Not respecting DEFAULT CURRENT_TIMESTAMP(6).
and the column `updatedAt` has a default of. NULL ON UPDATE CURRENT_TIMESTAMP . The `addedAt` column should not have an ON UPDATE clause...
Read more >Adding createdAt and updatedAt Timestampable Fields
Let's do more magic! I always like to have createdAt and updatedAt fields on my database tables. A lot of times, this helps...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This will be fixed in next release. The relevant PR is https://github.com/prisma/prisma-engines/pull/3200
@andrewicarlson