#Adding "createdAt" and "updatedAt" into existing table with some data. Procedure, anyone?

1 messages · Page 1 of 1 (latest)

frigid pewter
#

Title says it all. I'm trying to add the fields midstream. Prisma complains: "Step 0 Added the required column updatedAt to the business table without a default value. There are 23 rows in this table, it is not possible to execute this step. You can use prisma migrate dev --create-only to create the migration file, and manually modify it to address the underlying issue(s). Then run prisma migrate dev to apply it and verify it works." I tried the create-only route but I'm not sure the next steps to backfill the attributes for the existing records. Googling seems to lead to some sites that that don't really explain the full procedure. Anyone have a github or know of any resource that explains this common ( I'm assuming) situation?

wintry perchBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

sage vessel
# frigid pewter Title says it all. I'm trying to add the fields midstream. Prisma complains: "...

since there are existing rows in the table, you need to configure what you want the createdAt and updatedAt fields for those rows to be

  • if you want them to be null, just declare them as nullable to prisma with ?

  • if you want them to be the current date, add @default(now())

  • if you want to specify a different value then you'll need to do the two-step migration that prisma mentioned. it is unlikely this is what you want so i won't go into details for now.

frigid pewter