-
Original schema model Vendor {
id Int @id @default(autoincrement())
email String @unique
imageUrl String?
name String?
role Role @default(VENDOR)
vendorStrings VendorString[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model VendorString {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @unique
vendor Vendor @relation(fields: [vendorId], references: [id])
vendorId Int
}
enum Role {
VENDOR
ADMIN
} I want to make the model Vendor {
id Int @id @default(autoincrement())
email String @unique
imageUrl String?
name String?
role Role @default(VENDOR)
vendorStrings VendorString[] @relation(references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model VendorString {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @unique
vendor Vendor[] @relation(references: [id])
}
enum Role {
VENDOR
ADMIN
} How do I make it happen with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @Jayanth1991
This is currently the approach that you can follow to safely migrate from 1-n to m-n relations. |
Beta Was this translation helpful? Give feedback.
-
I just came across this issue with migrating columns like Maybe something like this. steps: [
{
"tag": "CreateField",
"model": "User",
"field": "firstName",
"type": "String",
},
{
"tag": "CreateField",
"model": "User",
"field": "lastName",
"type": "String",
},
{
"dataTransformer": splitUserNamesAndSave()
},
{
"tag": "DeleteField",
"model": "User",
"field": "name",
}
] |
Beta Was this translation helpful? Give feedback.
Hey @Jayanth1991
Currently
prisma migrate
doesn't support directly converting scalar fields to a list without data loss.For that, you would have to run your migrations in the following manner.
This is currently the approach that you can follow to safely migrate from 1-n to m-n relations.