Upgrade path for @relation from preview to beta #2048
-
I just read through the release notes about the new @relation syntax. While the more complicated syntax is a bit of a bummer, I can understand why it’s probably needed. But what I’m not clear on is how to upgrade to it? If I have this: model User {
id Int @id @default(autoincrement())
profile Profile
}
model Profile {
id Int @id @default(autoincrement())
user User
} And change it to this: model User {
id Int @id @default(autoincrement())
profile Profile
}
model Profile {
id Int @id @default(autoincrement())
+ user User @relation(fields: [userId], references: [id])
+ userId Int // relation scalar field (used in the `@relation` attribute above)
} If I run |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi, If you are an existing preview user, you can run There is also an issue which looks into simplifying the syntax for some common scenarios: #2018 |
Beta Was this translation helpful? Give feedback.
-
Hey Brandon 👋 I've added a new section to the top of the release notes that explains the concrete upgrade path for the relation syntax! Basically you don't need to touch the DB and can manually adjust your Prisma schema like so: model User {
id Int @id @default(autoincrement())
profile Profile?
}
model Profile {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
+ userId Int @map("user") // relation scalar field (used in the `@relation` attribute above)
}
model Post {
id Int @id @default(autoincrement())
author User @relation(fields: [authorId], references: [id])
+ authorId Int @map("author") // relation scalar field (used in the `@relation` attribute above)
} |
Beta Was this translation helpful? Give feedback.
Hey Brandon 👋 I've added a new section to the top of the release notes that explains the concrete upgrade path for the relation syntax!
Basically you don't need to touch the DB and can manually adjust your Prisma schema like so: